Solving Fibonacci NumberTo see the question, click here. Naive Approach The idea is to use a recursive approach to compute the Fibonacci sequence. If n is 0 or 1, return n directly, as these are the base cases for the Fibonacci sequence. For any other value of n, recursivel...4 min read·vineethchivukula.hashnode.devJul 14, 2024
Solving Next Greater Element ITo see the question, click here. Naive Approach The idea is to iterate through each element in nums1 and then search for this element in nums2. Once found, look for the next greater element in nums2 by scanning the elements following the found elemen...5 min read·vineethchivukula.hashnode.devJul 13, 2024
Solving Merge k Sorted ListsTo see the question, click here. Naive Approach The idea is to store all the values of the list nodes in an array, sort them using the Arrays.sort method, and then construct the linked list to return it as the answer. // TC: O(nlogn) // SC: O(n) imp...6 min read·vineethchivukula.hashnode.devJul 12, 2024
Solving Find Median from Data StreamTo see the question, click here. Naive Approach The idea is to store the elements in a list. At each stage of adding an element, we will sort the list because the elements may not be added to the list in a sorted fashion. // TC: O(nlogn) for addNum a...5 min read·vineethchivukula.hashnode.devJul 11, 2024
Solving Kth Largest Element in an ArrayTo see the question, click here. Naive Approach To find the kth largest element, we can first sort the array and then return the nums.length - k th element. // TC: O(nlogn) // SC: O(1) import java.util.Arrays; class KthLargestElement { public ...5 min read·vineethchivukula.hashnode.devJul 10, 2024