Rotate List Leetcode Solution

The problem Rotate List Leetcode Solution provides us a linked list and an integer. We are told to rotate the linked list to the right by k places. So if we rotate a linked list k places to the right, in each step we take the last element from the …

Read more

Search in Rotated Sorted Array Leetcode Solution

Consider a sorted array but one index was picked and the array was rotated at that point. Now, once the array has been rotated you are required to find a particular target element and return its index. In case, the element is not present, return -1. The problem is generally …

Read more

Longest subarray not having more than K distinct elements

The problem “Longest subarray not having more than K distinct elements” states that suppose you have an array of integers, the problem statement asks to find out the longest sub-array that having not greater than k different elements. Example   arr[] = {4, 3, 5, 2, 1, 2, 0, 4, 5} …

Read more

Binary Search Tree Delete Operation

Problem Statement   The problem “Binary Search Tree Delete Operation” asks us to implement the delete operation for binary search tree. Delete function refers to the functionality to delete a node with a given key/data. Example   Input Node to be deleted = 5 Output Approach for Binary Search Tree Delete Operation   So …

Read more

Best Time to Buy and Sell Stock

Problem Statement   The problem “Best Time to Buy and Sell Stock” states that you are given an array of prices of length n, where the ith element stores the price of stock on ith day. If we can make only one transaction, that is, to buy on one day and …

Read more