Skip to content

Commit ac5e609

Browse files
SUDO PLACEMENT 2019
1 parent 4c97ab0 commit ac5e609

File tree

1 file changed

+73
-1
lines changed

1 file changed

+73
-1
lines changed

GeeksForGeeks/sudo placement 2019.ipynb

+73-1
Original file line numberDiff line numberDiff line change
@@ -2927,12 +2927,84 @@
29272927
" print(r)"
29282928
]
29292929
},
2930+
{
2931+
"cell_type": "code",
2932+
"execution_count": 1,
2933+
"metadata": {},
2934+
"outputs": [],
2935+
"source": [
2936+
"a=[1,2,3,4,5,6,7,8,9]"
2937+
]
2938+
},
2939+
{
2940+
"cell_type": "code",
2941+
"execution_count": 2,
2942+
"metadata": {},
2943+
"outputs": [],
2944+
"source": [
2945+
"b=[1,2,3,4,5,7,8,9]"
2946+
]
2947+
},
2948+
{
2949+
"cell_type": "code",
2950+
"execution_count": 11,
2951+
"metadata": {},
2952+
"outputs": [
2953+
{
2954+
"name": "stdout",
2955+
"output_type": "stream",
2956+
"text": [
2957+
"6\n"
2958+
]
2959+
}
2960+
],
2961+
"source": [
2962+
"print(list(set(a)^set(b))[0])"
2963+
]
2964+
},
29302965
{
29312966
"cell_type": "code",
29322967
"execution_count": null,
29332968
"metadata": {},
29342969
"outputs": [],
2935-
"source": []
2970+
"source": [
2971+
"# Shortest path from 1 to n ---> Accolite, Cisco, Morgan Stanley, Samsung, Synopsys\n",
2972+
"# Difficulty: Basic   Marks: 1\n",
2973+
"'''\n",
2974+
"Consider a directed graph whose vertices are numbered from 1 to n. There is an edge from a vertex i to a vertex j iff either j = i + 1 or j = 3i. The task is to find the minimum number of edges in a path in G from vertex 1 to vertex n.\n",
2975+
"\n",
2976+
"Input: \n",
2977+
"The first line of input contains an integer T denoting the number of test cases. The description of T test cases follows.\n",
2978+
"\n",
2979+
"Each test case contains a value of n. \n",
2980+
"\n",
2981+
"Output: \n",
2982+
"Print the number of edges in the shortest path from 1 to n.\n",
2983+
"\n",
2984+
"Constraints:\n",
2985+
"1<=T<=30\n",
2986+
"1<=n <=1000\n",
2987+
"\n",
2988+
"Example:\n",
2989+
"Input:\n",
2990+
"2\n",
2991+
"9\n",
2992+
"4\n",
2993+
"\n",
2994+
"Output:\n",
2995+
"2\n",
2996+
"2\n",
2997+
"'''\n",
2998+
"def do(n):\n",
2999+
" if n<2:\n",
3000+
" return 0\n",
3001+
" if n==2:\n",
3002+
" return 1 \n",
3003+
" return ((n%3)+1+do(n//3))\n",
3004+
"for _ in range(int(input())):\n",
3005+
" n=int(input())\n",
3006+
" print(int(do(n)))"
3007+
]
29363008
}
29373009
],
29383010
"metadata": {

0 commit comments

Comments
 (0)