vineethchivukula.hashnode.devSolving 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...Jul 14, 2024·4 min read
vineethchivukula.hashnode.devSolving 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...Jul 13, 2024·5 min read
vineethchivukula.hashnode.devSolving 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...Jul 12, 2024·6 min read
vineethchivukula.hashnode.devSolving 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...Jul 11, 2024·5 min read
vineethchivukula.hashnode.devSolving 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 ...Jul 10, 2024·5 min read