Array Programs

Description

This includes the idea to solve different Array questions.
Subash M
Flashcards by Subash M, updated more than 1 year ago
Subash M
Created by Subash M about 7 years ago
18
0

Resource summary

Question Answer
Find the missing number, frequency of elements 1) 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.
Maximum sum, no two elements are adjacent Inclusion and exclusion way 1) include first element 2) excl_new = max ( incl, excl) 3) incl = excl + arr[i] 4) excl = excl_new
Sort an array of 0's and 1's 1)Take L and R pointer. 2) if arr[i] == 0 , L++ 3) if arr[i] == 1, R-- 4) swap(L, R)
Sort an array of 0's, 1's and 2's 1) 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--
Product 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
Median in a Stream of integers 1) 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
Min length Unsorted Array, sorting which make the array sorted 1) 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
Form Min No for given Sequence I = 12 D = 21 ID = 132 1) Maintain a stack 2) Push for every iteration 3) "I" = pop all and print
Count all pair with sum K Use hash and get the other element from difference with the sum K
Minimum no of Steps in Infinite Grid |_|_|_| |_|_|_| |_|_|_| (0,0)--> (1,1)=1 step. Can move in 8 dirs abs of x and y coordinate Max of these two
Show full summary Hide full summary

Similar

Computing Hardware - CPU and Memory
ollietablet123
SFDC App Builder 2
Parker Webb-Mitchell
Data Types
Jacob Sedore
Intake7 BIM L1
Stanley Chia
Software Processes
Nurul Aiman Abdu
Design Patterns
Erica Solum
CCNA Answers – CCNA Exam
Abdul Demir
Abstraction
Shannon Anderson-Rush
Spyware
Sam2
HTTPS explained with Carrier Pigeons
Shannon Anderson-Rush
Data Analytics
anelvr