Minimum operations required to transform a sequence of numbers to a sequence where a[i]=a[i+2]
Given a sequence of integers of even length ‘n’, the task is to find the minimum number of operations required to convert the sequence to follow the rule a[i]=a[i+2] where ‘i’ is the index. The operation here is to replace any element of the sequence with any element....
read more
Length of smallest subarray to be removed to make sum of remaining elements divisible by K
Given an array arr[] of integers and an integer K, the task is to find the length of the smallest subarray that needs to be removed such that the sum of remaining array elements is divisible by K. Removal of the entire array is not allowed. If it is impossible, then print “-1”....
read more
Longest subarray having maximum sum
Given an array arr[] containing n integers. The problem is to find the length of the subarray having maximum sum. If there exists two or more subarrays with maximum sum then print the length of the longest subarray.Examples:...
read more
Walmart Labs Interview Experience | Set 3 (On-Campus)
Walmart Labs Interview Experience – On campus...
read more
Count all prime numbers that can be formed using digits of a given number
Given a string S consisting of N digits, the task is to find the number of distinct Prime Numbers that can be formed using the digits of the string S....
read more
Maximum Tip Calculator
Rahul and Ankit are the only two waiters in the Royal Restaurant. Today, the restaurant received N orders. The amount of tips may differ when handled by different waiters and given as arrays A[] and B[] such that if Rahul takes the ith Order, he would be tipped A[i] rupees, and if Ankit takes this order, the tip would be B[i] rupees....
read more
Count quadruplets with sum K from given array
Given an array arr[] of size N and an integer S, the task is to find the count of quadruplets present in the given array having sum S....
read more
HashSet vs TreeSet in Java
When it comes to discussing differences between Set the firstmost thing that comes into play is the insertion order and how elements will be processed. HashSet in java is a class implementing the Set interface, backed by a hash table which is actually a HashMap instance. This class permits the null element. The class also offers constant time performance for the basic operations like add, remove, contains, and size assuming the hash function disperses the elements properly among the buckets while TreeSet is an implementation of the SortedSet interface which as the name suggests uses the tree for storage purposes where here the ordering of the elements is maintained by a set using their natural ordering whether or not an explicit comparator is provided....
read more
Clone a Binary Tree with Random Pointers
Given a Binary Tree where every node has the following structure....
read more
Next Greater Frequency Element
Given an array, for each element find the value of the nearest element to the right which is having a frequency greater than that of the current element. If there does not exist an answer for a position, then make the value ‘-1’....
read more
LinkedHashMap and LinkedHashSet in Java
The LinkedHashMap is just like HashMap with an additional feature of maintaining an order of elements inserted into it. HashMap provided the advantage of quick insertion, search, and deletion but it never maintained the track and order of insertion which the LinkedHashMap provides where the elements can be accessed in their insertion order....
read more
HashMap replace(key, oldValue, newValue) method in Java with Examples
The replace(K key, V oldValue, V newValue) method of Map interface, implemented by HashMap class is used to replace the old value of the specified key only if the key is previously mapped with the specified old value....
read more