Skip to content

Commit 6465a02

Browse files
SUDO PLACEMENT 2019
1 parent c3650f0 commit 6465a02

File tree

1 file changed

+290
-14
lines changed

1 file changed

+290
-14
lines changed

GeeksForGeeks/sudo placement 2019.ipynb

Lines changed: 290 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,112 @@
453453
" print(a[i-1])"
454454
]
455455
},
456+
{
457+
"cell_type": "code",
458+
"execution_count": 4,
459+
"metadata": {},
460+
"outputs": [
461+
{
462+
"name": "stdout",
463+
"output_type": "stream",
464+
"text": [
465+
"1\n",
466+
"5\n",
467+
"3 1 2 5 4\n",
468+
"5 3 1 4 2\n"
469+
]
470+
}
471+
],
472+
"source": [
473+
"# Print an array in Pendulum Arrangement ---> FactSet\n",
474+
"# Difficulty: Basic   Marks: 1\n",
475+
"'''\n",
476+
"Write a program to input a list of n integers in an array and arrange them in a way similar to the to-and-fro movement of a Pendulum.\n",
477+
"\n",
478+
"The minimum element out of the list of integers, must come in center position of array. If there are even elements, then minimum element should be moved to (n-1)/2 index (considering that indexes start from 0)\n",
479+
"The next number (next to minimum) in the ascending order, goes to the right, the next to next number goes to the left of minimum number and it continues like a Pendulum.\n",
480+
"Input:\n",
481+
"The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains an integer n denoting the size of the array. Then next line contains N space separated integers forming the array.\n",
482+
"\n",
483+
"Output:\n",
484+
"Output the array in Pendulum Arrangement.\n",
485+
"\n",
486+
"Constraints:\n",
487+
"1<=T<=500\n",
488+
"1<=N<=100\n",
489+
"1<=a[i]<=1000\n",
490+
"\n",
491+
"Example:\n",
492+
"Input:\n",
493+
"2\n",
494+
"5\n",
495+
"1 3 2 5 4\n",
496+
"5\n",
497+
"11 12 31 14 5\n",
498+
"\n",
499+
"Output:\n",
500+
"5 3 1 2 4\n",
501+
"31 12 5 11 14\n",
502+
"'''\n",
503+
"for _ in range(int(input())):\n",
504+
" n=int(input())\n",
505+
" a=list(map(int,input().split()))\n",
506+
" a.sort(reverse=True)\n",
507+
" if len(a)%2!=0:\n",
508+
" print(*(a[::2]),end=' ')\n",
509+
" else:\n",
510+
" print(*(a[1::2]),end=' ')\n",
511+
" print(*(a[-2::-2]))"
512+
]
513+
},
514+
{
515+
"cell_type": "code",
516+
"execution_count": 11,
517+
"metadata": {},
518+
"outputs": [
519+
{
520+
"name": "stdout",
521+
"output_type": "stream",
522+
"text": [
523+
"1\n",
524+
"86 41\n",
525+
"3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 19 21 22 23 24 25 27 28 29 30 31 32 33 34 35 36 39 40 42 43 45 46 47 48 49 50 51 52 53 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 74 75 76 78 79 81 82 84 85 87 88 89 90 91 92 93 95 96 97 98 99 100 101 102\n",
526+
"40\n"
527+
]
528+
}
529+
],
530+
"source": [
531+
"for _ in range(int(input())):\n",
532+
" n1,n2=map(int,input().split())\n",
533+
" a=list(map(int,input().split()))\n",
534+
" a.append(n2)\n",
535+
" a.sort()\n",
536+
" for i in range(len(a)):\n",
537+
" if a[-1]==n2:\n",
538+
" print(a[-2])\n",
539+
" break\n",
540+
" else:\n",
541+
" if a[i]==n2:\n",
542+
" if a[i+1]==n2:\n",
543+
" print(n2)\n",
544+
" break\n",
545+
" else:\n",
546+
" if (a[i-1]//n2)==(a[i+1]//n2):\n",
547+
" if (a[i-1]%n2)>(a[i+1]%n2) or (a[i-1]%n2)==(a[i+1]%n2):\n",
548+
" print(a[i+1])\n",
549+
" break\n",
550+
" else:\n",
551+
" print(a[i-1])\n",
552+
" break\n",
553+
" else:\n",
554+
" if (a[i-1]//n2)>(a[i+1]//n2):\n",
555+
" print(a[i+1])\n",
556+
" break\n",
557+
" else:\n",
558+
" print(a[i-1])\n",
559+
" break"
560+
]
561+
},
456562
{
457563
"cell_type": "code",
458564
"execution_count": 2,
@@ -461,7 +567,7 @@
461567
{
462568
"data": {
463569
"text/plain": [
464-
"[55, 9, 7, 6, 6, 5, 5, 4, 3, 3, 1, 1]"
570+
"4"
465571
]
466572
},
467573
"execution_count": 2,
@@ -470,34 +576,204 @@
470576
}
471577
],
472578
"source": [
473-
"a=[1,3,4,5,6,7,3,1,9,6,55,5]\n",
474-
"a.sort(reverse=True)\n",
579+
"n1"
580+
]
581+
},
582+
{
583+
"cell_type": "code",
584+
"execution_count": 3,
585+
"metadata": {},
586+
"outputs": [
587+
{
588+
"data": {
589+
"text/plain": [
590+
"int"
591+
]
592+
},
593+
"execution_count": 3,
594+
"metadata": {},
595+
"output_type": "execute_result"
596+
}
597+
],
598+
"source": [
599+
"type(n1)"
600+
]
601+
},
602+
{
603+
"cell_type": "code",
604+
"execution_count": 9,
605+
"metadata": {},
606+
"outputs": [
607+
{
608+
"data": {
609+
"text/plain": [
610+
"[3,\n",
611+
" 4,\n",
612+
" 5,\n",
613+
" 6,\n",
614+
" 7,\n",
615+
" 8,\n",
616+
" 9,\n",
617+
" 10,\n",
618+
" 11,\n",
619+
" 12,\n",
620+
" 13,\n",
621+
" 14,\n",
622+
" 15,\n",
623+
" 16,\n",
624+
" 17,\n",
625+
" 19,\n",
626+
" 21,\n",
627+
" 22,\n",
628+
" 23,\n",
629+
" 24,\n",
630+
" 25,\n",
631+
" 27,\n",
632+
" 28,\n",
633+
" 29,\n",
634+
" 30,\n",
635+
" 31,\n",
636+
" 32,\n",
637+
" 33,\n",
638+
" 34,\n",
639+
" 35,\n",
640+
" 36,\n",
641+
" 39,\n",
642+
" 40,\n",
643+
" 41,\n",
644+
" 42,\n",
645+
" 43,\n",
646+
" 45,\n",
647+
" 46,\n",
648+
" 47,\n",
649+
" 48,\n",
650+
" 49,\n",
651+
" 50,\n",
652+
" 51,\n",
653+
" 52,\n",
654+
" 53,\n",
655+
" 55,\n",
656+
" 56,\n",
657+
" 57,\n",
658+
" 58,\n",
659+
" 59,\n",
660+
" 60,\n",
661+
" 61,\n",
662+
" 62,\n",
663+
" 63,\n",
664+
" 64,\n",
665+
" 65,\n",
666+
" 66,\n",
667+
" 67,\n",
668+
" 68,\n",
669+
" 69,\n",
670+
" 70,\n",
671+
" 71,\n",
672+
" 72,\n",
673+
" 74,\n",
674+
" 75,\n",
675+
" 76,\n",
676+
" 78,\n",
677+
" 79,\n",
678+
" 81,\n",
679+
" 82,\n",
680+
" 84,\n",
681+
" 85,\n",
682+
" 87,\n",
683+
" 88,\n",
684+
" 89,\n",
685+
" 90,\n",
686+
" 91,\n",
687+
" 92,\n",
688+
" 93,\n",
689+
" 95,\n",
690+
" 96,\n",
691+
" 97,\n",
692+
" 98,\n",
693+
" 99,\n",
694+
" 100,\n",
695+
" 101,\n",
696+
" 102]"
697+
]
698+
},
699+
"execution_count": 9,
700+
"metadata": {},
701+
"output_type": "execute_result"
702+
}
703+
],
704+
"source": [
475705
"a"
476706
]
477707
},
478708
{
479709
"cell_type": "code",
480-
"execution_count": 4,
710+
"execution_count": 5,
711+
"metadata": {},
712+
"outputs": [],
713+
"source": [
714+
"a.append(n2)"
715+
]
716+
},
717+
{
718+
"cell_type": "code",
719+
"execution_count": 9,
720+
"metadata": {},
721+
"outputs": [
722+
{
723+
"data": {
724+
"text/plain": [
725+
"['1', '2', '4', '7', 6]"
726+
]
727+
},
728+
"execution_count": 9,
729+
"metadata": {},
730+
"output_type": "execute_result"
731+
}
732+
],
733+
"source": [
734+
"a"
735+
]
736+
},
737+
{
738+
"cell_type": "code",
739+
"execution_count": 7,
740+
"metadata": {},
741+
"outputs": [
742+
{
743+
"ename": "AttributeError",
744+
"evalue": "'list' object has no attribute 'find'",
745+
"output_type": "error",
746+
"traceback": [
747+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
748+
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
749+
"\u001b[0;32m<ipython-input-7-de2d9ce75c48>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0ma\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfind\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mn2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
750+
"\u001b[0;31mAttributeError\u001b[0m: 'list' object has no attribute 'find'"
751+
]
752+
}
753+
],
754+
"source": [
755+
"a.find(n2)"
756+
]
757+
},
758+
{
759+
"cell_type": "code",
760+
"execution_count": 2,
481761
"metadata": {},
482762
"outputs": [
483763
{
484764
"name": "stdout",
485765
"output_type": "stream",
486766
"text": [
487-
"1\n",
488-
"5\n",
489-
"3 1 2 5 4\n",
490-
"5 3 1 4 2\n"
767+
"70821\n"
491768
]
492769
}
493770
],
494771
"source": [
495-
"for _ in range(int(input())):\n",
496-
" n=int(input())\n",
497-
" a=list(map(int,input().split()))\n",
498-
" a.sort(reverse=True)\n",
499-
" print(*(a[::2]),end=' ')\n",
500-
" print(*(a[1::2]))"
772+
"c=0\n",
773+
"for i in range(100,1000):\n",
774+
" if i%7==3:\n",
775+
" c+=i\n",
776+
"print(c)"
501777
]
502778
},
503779
{

0 commit comments

Comments
 (0)