How to Find Kth Smallest Element In Unsorted Array

In this example, we’ll find Kth smallest element in unsorted array: K=2 means we want to find 2nd smallest number in the given array and to find the value it’s important to sort the array in the first place. 1. Java Using Arrays.sort() method: Output: Using Insertion Sort: Output: Complete Java Solutions can be found …

Read more

How to Find Intersection Of Two Sorted Arrays

In this example, we’ll find intersection of two sorted arrays: 1. Java #Approach 1 To find the intersection of 2 sorted arrays, follow the below approach : Use two variables with nested loop, i and j Compare elements to each other arr1[i] == arr2[j] If matches, print the element (or append). Output: #Approach 2 To …

Read more