Root to Leaf path with target sum Leetcode Solutions

A binary tree and an integer K are given. Our goal is to return whether there is a root-to-leaf path in the tree such that it’s sum is equal to the target-K. The sum of a path is the sum of all nodes that lie on it. 2 / \ …

Minimum Number of Steps to Make Two Strings Anagram Leetcode Solutions

Problem Statement In this problem, we are given two strings ‘s’ & ‘t’ consisting of lower-case English characters. In one operation, we can choose any character in string ‘t’ and change it to some other character. We need to find the minimum number of such operations to make ‘t’ an …

Problem Statement In the problem “License Key Formatting”, the input consists of a string of characters, representing a license key. Initially, the string is separated into N + 1 groups(words) by N dashes in between. We are also given an integer K, and the goal is to format the string …

Split a String in Balanced Strings Leetcode Solution

Problem Statement In this problem, we are given a string of characters, containing only ‘R’ and ‘L’. We call a string balanced if it has the same number of ‘R’s and ‘L’s. We can split the given string into disjoint substrings. The goal is to find the maximum possible number …

Kth Largest Element in a Stream Leetcode Solution

Problem Statement In this problem, we have to design a class KthLargest() that initially has an integer k and an array of integers. We need to write a parameterized constructor for it when an integer k and array nums are passed as arguments. The class also has a function add(val) that adds …

Sum of Even Numbers After Queries

Problem Statement In this problem, we are given an array of integer and array of arrays queries. For the ith query, we will have two parameters, index and val. After each query, we add val to array[index]. We need to find the sum of all even integers in the array after …

Remove Linked List Elements Leetcode Solution

Problem Statement In this problem, we are given a linked list with its nodes having integer values. We need to delete some nodes from the list which have value equal to val. The problem does not require to be solved in-place but we will discuss one such approach. Example List = …

Number Complement Leetcode Solution

Problem Statement In this problem, we are given a decimal number. The goal is to find its complement. Example N = 15 0 N = 5 2 Approach (Flipping bit by bit) We can flip every bit in the integer ‘N’ to get its complement. The important part is, we …

Combination Sum Leetcode Solution

The problem Combination Sum Leetcode Solution provides us an array or list of integers and a target. We are told to find the combinations that can be made using these integers any number of times that add up to the given target. So more formally, we can use the given …

Minimum Moves to Equal Array Elements Leetcode Solution

Problem Statement In this problem, we are given an array of integers. Also, we are allowed to perform a certain set of operations on this array. In one operation, we can increment ” n – 1″ (all elements except any one) elements in the array by 1. We need to …

Translate »