## 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 …

## Longest Substring Without Repeating Characters LeetCode Solution

Longest Substring Without Repeating Characters LeetCode Solution – Given a string, we have to find the length of the longest substring without repeating characters. Let’s look into a few examples: Example pwwkew 3 Explanation: Answer is “wke” with length 3 aav 2 Explanation: Answer is “av” with length 2 Approach-1 …

## An Interesting Method to generate Binary Numbers from 1 to n

Problem Statement The problem “An Interesting Method to generate Binary Numbers from 1 to n” states that you are given a number n, print all the numbers from 1 to n in binary form. Examples 3 1 10 11   6 1 10 11 100 101 110 Algorithm The generation …

## BST to a Tree with Sum of all Smaller Keys

In this problem we have given a Binary Search Tree, write an algorithm to convert best to a tree with sum of all smaller keys. Example Input Output Pre-order : 19 7 1 54 34 88 Naive Approach Traverse all the nodes one by one in any traversal form, and …

## Word Search

Word search is something like the word-finding puzzles at some time in our life. Today I bring to the table a modified crossword. My readers must be a bit perplexed as to what I am talking about. Without wasting any more time let us get to the problem statement Can …

## Smallest Element Repeated Exactly K Times

We are given an array A[] on size n. We have to find the smallest element that is repeated exactly k times in the array. Example Input A[]= {1, 2 ,2 ,5 ,5 ,2 ,5} K=3 Output Smallest element with frequency K is: 2 Approach 1: Brute force Main idea …

## Remove Minimum Number of Elements Such That no Common Element Exist in both Array

Given two arrays A and B consisting of n and m elements respectively. Remove minimum number of elements such that no common element exist in both array and print the count of elements which removed. Example Input: A[]={ 1, 2, 1, 1} B[]= {1, 1} Output: Minimum elements to remove …

## Sorting a Queue without Extra Space

In sorting a queue without extra space problem we have given a queue, sort it using standard queue operations without extra space. Examples Input queue = 10 -> 7 -> 2 -> 8 -> 6 Output queue = 2 -> 6 -> 7 -> 8 -> 10 Input queue = …

## Level order Traversal in Spiral Form

In this problem we have given a binary tree,  print its level order traversal in a spiral form. Examples Input Output 10 30 20 40 50 80 70 60 Naive Approach for Level order Traversal in Spiral Form The idea is to do a normal level order traversal using a …

## Trapping Rain Water LeetCode Solution

In the Trapping Rain Water LeetCode problem, we have given N non-negative integers representing an elevation map and the width of each bar is 1. We have to find the amount of water that can be trapped in the above structure. Example Let’s understand that by an example For the …

Translate »