Featured Article

Reverse Delete Algorithm for Minimum Spanning Tree

Reverse Delete algorithm is closely related to Kruskal’s algorithm. In Kruskal’s algorithm what we do is : Sort edges by increasing order of their weights. After sorting, we one by one pick edges in increasing order. We include current picked edge if by including this in spanning tree not form any cycle until there are… Read More »

Amazon Interview experience | Set 326 (For SDE II)

1st 1. reverse the linklist in pair manner Q: 1->2->3->4->5 A: 2->1->4->3->5 2. third highest value in tree Full code required. 2nd put the given random pointers in linklist to point to next greater node such that if u transverse list in using random pointer, list become sorted. duplicates are allowed. Full code required 3rd… Read More »

Constant time range add operation on an array

Given an array of size N which is initialized with all zeros. We are given many range add queries, which should be applied to this array. We need to print final updated array as our result. Examples: N = 6 Arr = [0, 0, 0, 0, 0, 0] rangeUpdate1 [0, 2], add 100 Arr =… Read More »

Covariant return types in Java

Before JDK 5.0, it was not possible to override a method by changing the return type. When we override a parent class method, the name, argument types and return type of the overriding method in child class has to be exactly same as that of parent class method. Overriding method was said to be invariant… Read More »

Sum of all Subarrays

Given an integer array ‘arr[]’ of size n, find sum of all sub-arrays of given array. Examples: Input : arr[] = {1, 2, 3} Output : 20 Explanation : {1} + {2} + {3} + {2 + 3} + {1 + 2} + {1 + 2 + 3} = 20 Input : arr[] = {1,… Read More »