Fichas
Array Programs
Fichas del conjunto (10)
- 1Find the missing number, frequency of elements1) Goto element's index and add n.
2) Iterate through the array and divide by n
3) mod every element by n to revert back. - 2Maximum sum, no two elements are adjacentInclusion and exclusion way
1) include first element
2) excl_new = max ( incl, excl)
3) incl = excl + arr[i]
4) excl = excl_new - 3Sort an array of 0's and 1's1)Take L and R pointer.
2) if arr[i] == 0 , L++
3) if arr[i] == 1, R--
4) swap(L, R) - 4Sort an array of 0's, 1's and 2's1) L, M = 0 and H = n-1
2) 0 - L = 0's, L - M = 1's, H - n-1 = 2's
3) Process M - H
4) if M=0, swap with L and L++, M++
5) if M=1, M++;
6) if M==2, Swap(M, H), M++, H-- - 5Product Array Puzzle Print Product of all array except arr[i]. without using "/" and in O(n)1) Have a Left array (Product of Nos on left)
2) Right array ( Product of Nos on right)
3) Multiply both the arrays - 6Median in a Stream of integers1) Insertion Sort
2) Use a left MaxHeap and right MinHeap
3) root median = side with max elements
4) equal size = average of top of 2 sides - 7Min length Unsorted Array, sorting which make the array sorted1) 1st element > next = s
2) 1st element < prev = e
3) Find min, max in (s,e)
4) 1st element > min = s
5) 1st element < max = e
answer = s, e - 8Form Min No for given Sequence I = 12 D = 21 ID = 1321) Maintain a stack
2) Push for every iteration
3) "I" = pop all and print - 9Count all pair with sum KUse hash and get the other element from difference with the sum K
- 10Minimum no of Steps in Infinite Grid |_|_|_| |_|_|_| |_|_|_| (0,0)--> (1,1)=1 step. Can move in 8 dirsabs of x and y coordinate
Max of these two
Información
- Descripción
- This includes the idea to solve different Array questions.
- Creado por
- Subash M
- Visitas
- 49
- Etiquetas
- Valoración