100 Day Coding Challenge
100 Day Coding Challenge
Instagram
100 Days Coding Ch
LinkedIn
QUESTION TRACKER
GOAL : To improve Problem Solving Skills by doing 250 Good D
163
250 Easy
Medium
Hard
Remainin
SUMMARY:
Total Done 163
Easy Easy 40
Medium
Medium 103
Hard
Hard 20
Remaining
Remaining 87
naya mtlb isme bhi alag hi direction me soch raha th: yeh quetion thoda ese confusing sa laga to understand
ahi bataya h ki yadi total sum <0 h toh answer -1 h other wise fir toh jaha negative h uske aage vale ko start kardo me zabardas
hi mene bhot bada code kara h bhot jabki 8 lines hi h basss bhot ahca intution lag gaya isse
ne ' ' kar liya toh answer galat aa raha tha aur me debug bhi nahi kar paa raha tha ki mistake kaha hue h!!
uestion dhang se padhna hi nahi ki numeric ko bhi consider karna h toh uss chakar me ek baar run karne me fail ho gaya toh is
se hi ho gaya
application h kyuki isme phle spaces hatane h and then fir uske baad alag alag words ko fir reverse karna h and then answer n
case ko thoda handle karne me galti ho sakti h toh uske liye sabse badiyaa tarika h ki final answer ham set me store karenge t
d intuiton thi ki fixed length ki hi substring hoti toh isse hame thought aana chaiye ki 2 pointer h
jo map ho rahe h ek dusre se toh yeh condition check nahi kara tha ki jo dusra charcter h vo already kisi se linked ya mapped t
empty "" string vala case nahi le raha tha uss chakar me galat h jataa h and iska optimised tarika yeh hoga ki sort karke bas firs
paaya tha kya approach lagau me kich ese soch raha tha ki heights ko store karke rakho ascending order me fir lowerbound n
mene ek choti si logic ki galti kardi thi toh mene usko run kara fir thoda debug kara toh samaj aagaya bhot hi minor logic me er
dge case me string me empty vali chez nahi dekhaa uss chakar me kaam fasss gaya toh string jab bhi ho toh empty vala case t
nd new!!! It uses Set with a very new approach My appraoch was with 4 for loop but inhone 2 loop me hi kardiya question solve
nder sirf ek hi coloumn ya row h toh usme vo duoble baar print kar de raha tha isi liye apn ko if condition lagani padegi check ka
dum 4 line ka sirff mene toh thoda lambaa tarike se kara
mple tarike se karliyaa: isko bina extra space use kare matrix ki first row and first coloum ko use kar skte h ki konsa row me ze
space use karne ke liye hamne same hi matrix me alag tarike se save kara vo chez badiya thi iss question ki and 8 durections
main chez thi toh uske liye stringstream use kar liyaa h function jisse words alag alag ho jate h and secodnly bijection function
hi solve kar skte h yeh mene submission me approach dekhaa o(1) space me: Circular LL ka variant h ek tarike se: https://leetc
g window kuch lagega but isme simply bas hashmap use hoga
se phle mene stack check nahi kara ki empty toh nhi th atoh vo ab dhyaan dena h ki pop ke phle hamesha check karna h secon
ax in K sliding window types hi question laga thoda but isme mene stack stl use kara h and jab mene solution tab me dekha toh
i thi initially vo yeh tha ki me ulta divide kar raha tha a/b ki jagah b/a kyuki mene jo phela top nikla usko me first consider kasr r
ahi kaaa paya toh me abhi solution dekha lekin usse bhi zada samaj ni aaya nahi h toh youtube video dekha h and then code k
o dummy banaya tha for heads of two LL toh usme mene dummy ka next current LL ka head kardiyaa tha jab ki NULL karna tha
yaa tha mene kuch aur fir baad me samaj aaya ki question alag h then fir isme basically meko flatten the binary tree h na vahi k
sakte h Pre ORDER traversal laga ke jo mene logo ke solutions dekhe toh samaj aaya Mene Level Order Traversal kara tha an
ke me kar raha tha ki node ko galti se answer me push kar raha tha jabki node->val karna tha toh vo bas ek baar error aaya th
da ho sakte h usme mere case fail ho gyaa tha kyuki mene int liya tha aur apn ko long lena padegaa
power ginna h and isme facto ke time hame yeh dekhna h ki 5,25,125 me jese multiplr 5 h uuske ander hi
aya isme bhi long long int lena padegaa varna fir yahi problem ho gae h same
ha h jisme 2^-31 ho rahi h toh isme kya h ki jab iss power ko positive kar rahe h na toh vo range ke bhaar chale jaa rahi h n ke
bas toh usme mene phle mx ko INT_MIN liya tha jo ki ab me lunga 1 tykuki minimum 1 to aaega hi line me
kkar me itna time laga vo yeh tha ki last me jab carry bach raha tha toh me usko add nahi kar raha tha
ha kyuki question me bola h binary string diya h ese unsigned_int toh meko laga ki yeh unsigned int as an integer hi h na ki bin
ber we will use right shift operator
ement 0 hota hai
apn ko basically bit pe jaake sum karna h and then dekhna h divisble by 3 h toh mtlb
o solution tab me 4 line ka code h vo mastt badiyaa laga: while(m!=n) vali condition https://leetcode.com/problems/bitwise-and-
48secs me karliyaa tha lekin follow up question jo divide and conquer se karna tha usko sochne me time lag gaya kyuki me so
aiye h toh think of heap/priority queue. in this we are using min head so for that we will declare the priortiy queue as below: prior
ke baad heap use kara maximum nikalne ke liyee
n store karenge k smallest elemetn toh iske lioye max heap use karenge and jab bhi max heap ke top element se chota koe aae
x and min and ham array ko adhe adhe me store karenge and secondly isme ham rebalancing karenge haar baar jab bhi elemt
tha mtlb right kar raha tha jabki left value return karni thi yadi element naa mile toh
E BAAD BANA
ment index so in that we needed 6 conditions whoch became complex so we need to directly find the pivot element and solve s
me jo corner case h ki last aur first elemtn ka vo aher se handle nahi kara tha jiske vajah se error ayaa tha first time me fir vo re
kab left<right karna h kab left=mid karna h kab mid+1 karna h toh vo sab thoda sochne samjhne me time chala gaya iss quest
kin log(n) vala nahi ho paya toh uss vajah se fir
di mtlb mujhe samaj nahi aa rha usse time limit exceed kyu aa rha h but usko pakande me itna zada time lag gaya bas ek varia
h us vajah se time lag gaya tha
a h and then build karna h
position pe hi blocker h toh uss case me toh fir answer zerpo hi h mene yeh case cover nahi kara tha
xceed kar raha tha kyuki me jab 2 length ka substring tha tab bhi recursion call kar raha tha toh zada calls lag jaa rahe the btw
h mene toh 4D DP se kara basically isko solve.Discussion dekhne ke baad toh lag rha h mene kitna subardastti complex kardi
(n) apply kara thoda silly mistake kar diyaa tha first wo and first coloumn valo ko max me naa consider karke jiske chakkar me
olution: Refer my Solution for understanding: https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv/submissions/113
ex check nahi kar raha tha vo galti kardi matrix me
* ka bana liya jisme old or new save kar rakha h node corresponsing
ECTED GRAPH: in this we have the current path and if any node is directing again to current paths node that means we have a
wer list ek aur chez add kardi h
nte isme waste kardiyee mene but hamesha yaad rakhnaa jab bhi single source se shortest distance nikalni h toh BFS use hot
apply kari h
ha kyuki '.' vali chez ko use karnaa h toh sare possible search karne padenge
peration lagega and intution yeh ki constraintn dekhnke samaj aaega ki backtracking hame use karni padegi but usko optimize
arne me fail ho gaya toh isi liye meko questions dhng se padhna h
karna h and then answer niklega final inplace without using any extra space!! Iske baad mene isko yadi function use karke bina
am set me store karenge toh fir duplicate vali chez haat jaegi: Isme thought yeh h ki jab bhi esa bola jae na ki answer me duplic
kisi se linked ya mapped toh nahi h esaa!!! toh uske liye ek hashmap. fir mene aur banaya jo denote kar raha h ki kon kon se c
hoga ki sort karke bas first and last ko dekh lena h!!
order me fir lowerbound nikalenge esa karke kuch kuch fir baad me samaj aaya ki yeh toh 2 pointers se ho raha h sidhe sidhe a
a bhot hi minor logic me error tha ek line upar niche karne ka: Jab bhui subarray ka kuch nikalna h toh yeh intution rahega ki try
i ho toh empty vala case toh dekhna hi h
e hi kardiya question solve!!!!
on lagani padegi check karne k liye ki kya vo single row ya coloumn jo sabse ander h vo toh nhi h .....Isko sidha 4 pointer appr
kte h ki konsa row me zero hoga and konse coloumn me : Refer submission tab - https://leetcode.com/problems/set-matrix-ze
estion ki and 8 durections me search karne ke liye hamne sidha vector bana liya direction ka. vo bhi acha h logic !!
ecodnly bijection function bole toh 1 to one mapping isi me mene gali kardi thi ki jese same words alag alag char se maop kar d
m vali value milegi toh me uss hisab se code likh diya tha but usme fir usse kam: I used two hashmap it can be done using one
etcode.com/problems/insert-interval/solutions/1327206/99-16-faster-proper-explaination-c-solution-o-n/?envType=study-plan-v2
hi uske upar vale question same type me the toh vesa dimag chal gaya
esha check karna h secondl;y hamne base condition jisme koe directory nahi rahegi vo vala cover nahi kara tha toh usme hame
solution tab me dekha toh isko bina stl ke LinkedList se bhi kar sakte h toh vo interview ke hisab se acha laga https://leetcode.
ko me first consider kasr raha tha jabki vo second interger hoga operation me
o dekha h and then code kara usko
o next hi nhi kar raha toh infinite run ho jaa raha tha then fir upar head ko declare kara toh usko NULL nahi kara toh uski vajah s
raha h toh apn ko alag se usko address nahi karna padhta at the end apn ko bas dummu->next dena rehta h
issi liye dikat aa rahi thi
tha jab ki NULL karna tha otherwise cycle ban jaega when extreme case honge toh
the binary tree h na vahi karna h bas inordered me karna h toh isme pair return karna padh raha tha first and last node ka and
Order Traversal kara tha and last node ko har level ke store karna tha vector me last node find karne ke liye ham haar level ke e
solutions/99905/two-solutions-in-order-traversal-and-a-more-general-way-using-treeset/?envType=study-plan-v2&envId=top-int
apn ko LONG_MIN and LONG_MAX lena h otherwise jo INT_MAX vali value ka root hoga uska answer galat aa jaega
om/problems/bitwise-and-of-numbers-range/solutions/56729/bit-operation-solution-java/?envType=study-plan-v2&envId=top-int
time lag gaya kyuki me soch raha tha ki kuch tagdi approach hogi but vo toh simply mtlb preffix and suffix calculate karliyaa tha
element se chota koe aaega toh maxheap ko pop karenge andhten push kardenge naye sum ko
ge haar baar jab bhi elemtn add karenge toh kyuki hamesha halfs balanced hone chaiye infact hamne esa liya h ki left half me h
time lag gaya bas ek variable meko global set karna tha aur mene usko local kardiyaa toh uss chakkar me time limit exceed aa
calls lag jaa rahe the btw isko sidhaaa bina DP ke 2 pointer se bhi kar skte h toh baaad me mene usse bhi question try kara
subardastti complex kardiyaa tha question ko
nikalni h toh BFS use hota h naa ki DFS mene vahi galti kardi iss question me
ae na ki answer me duplicates na ho toh usko sidha set me store karo toh duplicate vali chez toh khtm hi ho jaegi usko alag se
se ho raha h sidhe sidhe and yeh mere vale approach se bhi ho jaega but usme doo baar fir iteration lagega mene yeh socha t
yeh intution rahega ki try karna sliding window ho sakta h
.Isko sidha 4 pointer approach se solve karelnge toh usme samjhana bhot aasan h
m/problems/set-matrix-zeroes/solutions/3172908/best-c-4-solution-hash-table-matrix-brute-force-optimize-one-stop-solution/?e
acha h logic !!
g alag char se maop kar diya tha toh vo nahi karn ah isi liye apn ko do map use karne h : https://www.geeksforgeeks.org/strings
ce-and-no-magic-math-property-involved/?envType=study-plan-v2&envId=top-interview-150
it can be done using one as well( saw that frm solution tab)
n/?envType=study-plan-v2&envId=top-interview-150
hi kara tha toh usme hame ek / lagana padega toh vo alag tairke se handle kara: mene isko karne me do stack use kar liya tha
acha laga https://leetcode.com/problems/min-stack/solutions/49010/clean-6ms-java-solution/?envType=study-plan-v2&envId=to
nahi kara toh uski vajah se pura answer phaatt raha tha mtlb vahi h ki yadi sirf code likhna start kar deta hu na bina likhetoh ku
first and last node ka and isme mene ek silly mistake bhi kardi thi uske chakkar me time chala gaya tha
udy-plan-v2&envId=top-interview-150
er galat aa jaega
udy-plan-v2&envId=top-interview-150
uffix calculate karliyaa tha. Refer this: https://leetcode.com/problems/maximum-subarray/solutions/1595195/c-python-7-simple
esa liya h ki left half me hi unbalanced ho yadi ho bhi toh. Isme yeh mistake ek krdi thi ki vector ki size nikal ke minus kar raha
etcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/solutions/14699/clean-iterative-solution-with-two-bin
lagega mene yeh socha tha ki right vale ko samjhenge jab vo minimum h uski hieght oh ham usse bade vali height ko hi dhund
mize-one-stop-solution/?envType=study-plan-v2&envId=top-interview-150
.geeksforgeeks.org/stringstream-c-applications/
do stack use kar liya tha lekin yeh ek stack me bhi ache se ho jata: https://leetcode.com/problems/simplify-path/solutions/1847
e=study-plan-v2&envId=top-interview-150
ze nikal ke minus kar raha tha uss chakkar me zada time lag gaya
mplify-path/solutions/1847357/c-easy-stack-simple-explained-algorithm/?envType=study-plan-v2&envId=top-interview-150
study-plan-v2&envId=top-interview-150
w-150 . Toh iss solution ko dekh ke yeh learning mili h ki jab bhi esi situation ho jisme element ko find karne ke baad bhi apni s
vId=top-interview-150
karne ke baad bhi apni search nahi rukni chaiye toh ese case me apn fir kya karenge ki while(left<right) and jo arr[mid]==targe
ght) and jo arr[mid]==target vali chez h vo hata ke l ya right me mid ki value assign karte jaaenge!!!
Youtube
Instagram
100 Days Coding Chal
LinkedIn
LEARNING TRACKER
GOAL : To improve Problem Solving Skills by doing 250 Good DSA Questions
Day Link
ng Challenge
by Siddharth Singh