"Leetcode 347: Heap + Hashtable
Follow up question: create heap with the length of K instead of N (more time complexity but less space )"
Chen J. - "Leetcode 347: Heap + Hashtable
Follow up question: create heap with the length of K instead of N (more time complexity but less space )"See full answer
"I try to solve this initially using quick select where will take a pivot element and position the remaining elements and check if the current index is answer or not and continue the same but it requires o(n*n), but interviewee is expecting the best from me, so at the end i tried solving using heaps where will check the difference between k and n-k to use min or max heap after that we will heap the array, and will keep popping the element k-1 and return the peek one which leads to answer."
Mourya C. - "I try to solve this initially using quick select where will take a pivot element and position the remaining elements and check if the current index is answer or not and continue the same but it requires o(n*n), but interviewee is expecting the best from me, so at the end i tried solving using heaps where will check the difference between k and n-k to use min or max heap after that we will heap the array, and will keep popping the element k-1 and return the peek one which leads to answer."See full answer
"filter function usually exists in some high level programming that adopt FP paradigm.
It taks a sequence of items and a predicate function, and returns (conceptually) a subset of the items that satisfy the predicate.
Adopt this kind of operation (filter, map, reduce, take, pairwise ...) can help writting
cleaner code, and reduce the usage of mutable part in the program, lower the
possibility of making human mistake.
Take Python for example (although const-ness is not exists in Python),
assu"
Weida H. - "filter function usually exists in some high level programming that adopt FP paradigm.
It taks a sequence of items and a predicate function, and returns (conceptually) a subset of the items that satisfy the predicate.
Adopt this kind of operation (filter, map, reduce, take, pairwise ...) can help writting
cleaner code, and reduce the usage of mutable part in the program, lower the
possibility of making human mistake.
Take Python for example (although const-ness is not exists in Python),
assu"See full answer
"We can use a pool of memory where each index we can store the parent of current index then we can use same lca approach for array instead of pointers."
Sourav K. - "We can use a pool of memory where each index we can store the parent of current index then we can use same lca approach for array instead of pointers."See full answer