Skip to content

Commit a274e85

Browse files
committed
repeatedNTimes
1 parent 2267f3c commit a274e85

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

.ipynb_checkpoints/lets code-checkpoint.ipynb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,36 @@
950950
"print(numJewelsInStones(\"z\",\"ZZ\"))"
951951
]
952952
},
953+
{
954+
"cell_type": "code",
955+
"execution_count": 7,
956+
"metadata": {},
957+
"outputs": [
958+
{
959+
"name": "stdout",
960+
"output_type": "stream",
961+
"text": [
962+
"3\n"
963+
]
964+
}
965+
],
966+
"source": [
967+
"# In a array A of size 2N, there are N+1 unique elements, and exactly one of these elements is repeated N times. \n",
968+
"# Return the element repeated N times.\n",
969+
"def repeatedNTimes(A):\n",
970+
" Hash = dict()\n",
971+
" size = len(A)//2\n",
972+
" for i in range(len(A)):\n",
973+
" if A[i] in Hash:\n",
974+
" Hash[A[i]] = Hash[A[i]] + 1\n",
975+
" else :\n",
976+
" Hash[A[i]]=1\n",
977+
" if(Hash[A[i]] == size):\n",
978+
" return A[i]\n",
979+
"\n",
980+
"print(repeatedNTimes([1,2,3,3]))"
981+
]
982+
},
953983
{
954984
"cell_type": "code",
955985
"execution_count": null,

lets code.ipynb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,36 @@
950950
"print(numJewelsInStones(\"z\",\"ZZ\"))"
951951
]
952952
},
953+
{
954+
"cell_type": "code",
955+
"execution_count": 7,
956+
"metadata": {},
957+
"outputs": [
958+
{
959+
"name": "stdout",
960+
"output_type": "stream",
961+
"text": [
962+
"3\n"
963+
]
964+
}
965+
],
966+
"source": [
967+
"# In a array A of size 2N, there are N+1 unique elements, and exactly one of these elements is repeated N times. \n",
968+
"# Return the element repeated N times.\n",
969+
"def repeatedNTimes(A):\n",
970+
" Hash = dict()\n",
971+
" size = len(A)//2\n",
972+
" for i in range(len(A)):\n",
973+
" if A[i] in Hash:\n",
974+
" Hash[A[i]] = Hash[A[i]] + 1\n",
975+
" else :\n",
976+
" Hash[A[i]]=1\n",
977+
" if(Hash[A[i]] == size):\n",
978+
" return A[i]\n",
979+
"\n",
980+
"print(repeatedNTimes([1,2,3,3]))"
981+
]
982+
},
953983
{
954984
"cell_type": "code",
955985
"execution_count": null,

0 commit comments

Comments
 (0)