Skip to content

Commit c88cf19

Browse files
committed
started top 150 interview questions
1 parent 52346be commit c88cf19

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed

leetcode_kuro_RnD.ipynb

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8802,6 +8802,128 @@
88028802
"\n"
88038803
]
88048804
},
8805+
{
8806+
"cell_type": "code",
8807+
"execution_count": 21,
8808+
"metadata": {},
8809+
"outputs": [
8810+
{
8811+
"name": "stdout",
8812+
"output_type": "stream",
8813+
"text": [
8814+
"['h', 'a', 'n', 'n', 'a', 'H']\n"
8815+
]
8816+
}
8817+
],
8818+
"source": [
8819+
"# 344 : https://leetcode.com/problems/reverse-string/\n",
8820+
"\n",
8821+
"s = [\"h\",\"e\",\"l\",\"l\",\"o\"]\n",
8822+
"s = [\"H\",\"a\",\"n\",\"n\",\"a\",\"h\"] # [\"h\",\"a\",\"n\",\"n\",\"a\",\"H\"]\n",
8823+
"\n",
8824+
"# for i in range(len(s)-1,-1,-1):\n",
8825+
"# s.insert(len(s)+1,s[i])\n",
8826+
"# s.remove(s[i])\n",
8827+
"# print(s)\n",
8828+
"\n",
8829+
"s[:] = s[::-1]\n",
8830+
"print(s)"
8831+
]
8832+
},
8833+
{
8834+
"cell_type": "code",
8835+
"execution_count": 3,
8836+
"metadata": {},
8837+
"outputs": [
8838+
{
8839+
"name": "stdout",
8840+
"output_type": "stream",
8841+
"text": [
8842+
"['h', 'e', 'l', 'l', 'o']\n",
8843+
"['h', 'e', 'l', 'l', 'o', 'p']\n"
8844+
]
8845+
}
8846+
],
8847+
"source": [
8848+
"s = [\"h\",\"l\",\"e\",\"l\",\"l\",\"o\"]\n",
8849+
"\n",
8850+
"s.remove(\"l\")\n",
8851+
"print(s)\n",
8852+
"s.insert(6,\"p\")\n",
8853+
"print(s)"
8854+
]
8855+
},
8856+
{
8857+
"cell_type": "code",
8858+
"execution_count": 25,
8859+
"metadata": {},
8860+
"outputs": [
8861+
{
8862+
"name": "stdout",
8863+
"output_type": "stream",
8864+
"text": [
8865+
"[[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]\n"
8866+
]
8867+
}
8868+
],
8869+
"source": [
8870+
"# 46 : https://leetcode.com/problems/permutations/\n",
8871+
"\n",
8872+
"import itertools as it\n",
8873+
"\n",
8874+
"nums = [1,2,3]\n",
8875+
"\n",
8876+
"nums_iter = list(map(list, list(it.permutations(nums,len(nums)))))\n",
8877+
"print(nums_iter)\n",
8878+
"\n",
8879+
"# for i,j in enumerate(nums_iter):\n",
8880+
"# j = list(j)\n",
8881+
"\n",
8882+
"# print(nums_iter)"
8883+
]
8884+
},
8885+
{
8886+
"cell_type": "code",
8887+
"execution_count": null,
8888+
"metadata": {},
8889+
"outputs": [],
8890+
"source": []
8891+
},
8892+
{
8893+
"cell_type": "code",
8894+
"execution_count": 20,
8895+
"metadata": {},
8896+
"outputs": [
8897+
{
8898+
"ename": "ValueError",
8899+
"evalue": "invalid literal for int() with base 10: '1 2 3 56'",
8900+
"output_type": "error",
8901+
"traceback": [
8902+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
8903+
"\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)",
8904+
"Cell \u001b[1;32mIn [20], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m n \u001b[39m=\u001b[39m \u001b[39mint\u001b[39;49m(\u001b[39minput\u001b[39;49m(\u001b[39m\"\u001b[39;49m\u001b[39mEnter number of elements : \u001b[39;49m\u001b[39m\"\u001b[39;49m))\n\u001b[0;32m 3\u001b[0m list_1 \u001b[39m=\u001b[39m \u001b[39mlist\u001b[39m(\u001b[39mmap\u001b[39m(\u001b[39mint\u001b[39m, \u001b[39minput\u001b[39m(\u001b[39m\"\u001b[39m\u001b[39m\\n\u001b[39;00m\u001b[39mEnter the numbers : \u001b[39m\u001b[39m\"\u001b[39m)\u001b[39m.\u001b[39mstrip()\u001b[39m.\u001b[39msplit()))[:n]\n\u001b[0;32m 4\u001b[0m \u001b[39mprint\u001b[39m(\u001b[39m\"\u001b[39m\u001b[39m\\n\u001b[39;00m\u001b[39mList is - \u001b[39m\u001b[39m\"\u001b[39m, list_1)\n",
8905+
"\u001b[1;31mValueError\u001b[0m: invalid literal for int() with base 10: '1 2 3 56'"
8906+
]
8907+
}
8908+
],
8909+
"source": [
8910+
"n = int(input(\"Enter number of elements : \"))\n",
8911+
"\n",
8912+
"list_1 = list(map(int, input(\"\\nEnter the numbers : \").strip().split()))[:n]\n",
8913+
"print(\"\\nList is - \", list_1)\n",
8914+
"def absolute_value(num):\n",
8915+
" return abs(num)\n",
8916+
"\n",
8917+
"\n",
8918+
"list_2 = list_1.sort(key = absolute_value)\n",
8919+
"print(list_2)\n",
8920+
"def length_of_list(list_2):\n",
8921+
" for i in list_2:\n",
8922+
" for j in list_2:\n",
8923+
" if abs(i) == abs(j) and i < j:\n",
8924+
" print('here')"
8925+
]
8926+
},
88058927
{
88068928
"cell_type": "markdown",
88078929
"metadata": {},

0 commit comments

Comments
 (0)