Posts

Showing posts from October, 2024

interview tips

1. tell soln FROM BRUTE TO BETTER TO OPTIMAL 2. Give good names to func &  var. EXTRA SPACE USED  means jo given hai unhe exclude karke space complexity batani hai.                                                                                VS SPACE USED in algorithm means include karke. 4. never deep down in brute solution in interview. just tell upar upar se. 5. tell method/steps upar upar se and u need not code in interview also. 6. Don't make global variables in soln to an interview ques. ----------------------------- 7. don't change original given thing instead u may make a copy of it 8. binary search mein main thing is ye pehchanna ki kya eliminate krna hai ⭐9. for questions involving duplicates , make code for uniques and modify la...

12. arrays easy

Image
  Array contains elements with similar data types int arr[n]==> garbage values if inside main                ==> 0s if globally. -------------------------------------------------------------------------------- rotate✅   intersectionšŸ”„ all zeros to end✅ missing number✅ number appears once✅ longest subarray with sum kšŸ”„ Largest, 2nd largest✅ remove duplicates✅ union✅ max consecutive 1s✅ sorted check✅ -------------- -------------------------------------------------------------------                                                          LARGEST Ans- (for positive elements) BRUTE (nlogn)- sort it and then do as asked OPTIMAL (n)-use loops ---------------------------------------------------------------------------------            ...

11. Quick sort⭐

Image
Divide & Conquer algorithm time- NlogN,    space- 1 pick a pivot & place it in its correct position in sorted array -------------------------------------------------------------------------------------------------------------------------- 1. make low and high 2. choose pivot 3. take 2 pointers i=low & j=high 4. if, a[i] > pivot  &    a[j]<= pivot,  swap the two else i++ and j-- 5. for one round do this till,  i>j 6. last mein pivot se swap karo 7. ab partition bangya, so  put pivot in right place--> sort left and right half ------------------------------------------------------------------------------------------------------------------------ --------------------------------------------------------------------------------------------------------------------------

10. merge sort

Image
time complexity- O (NlogN) space complexity- O(N) -----------------------------------------------------------------------------------                                                 -------------------------------------------------------------------------------------------------------------------------

9. bubble, selection, insertion SORT

Image
Selection Sort  O(N^2) minimum uthake poore me se ith wale se swap maardo ---------------------------------------------------------------------------------------------------------------                                                                                                                              Bubble Sort  O(N^2) max walo ko last m bhejdo... ------------------------------------------------------------------------------------------------------------------------- Insertion Sort  O(N^2) front se chote chote array leke dekhte jao, har baar ek se size badha do... un chote arrays me piche se aa...

8. hashing

Image
Hash Array: pre-storing in a hash array/ freq array to reduce time complexity  ------------------------------------------------------------------------------------------------------------                             Character hashing -                       1.  without hashing-   2.   with hashing-       or -------------------------------------------------------------------------------------------------------------                                                                         Mapping- --------------------------------------------------------------------------------...