First Unique Character in a String LeetCode Solution

Problem Statement First Unique Character in a String LeetCode Solution – Given a string s, find the first non-repeating character in it and return its index. If it does not exist, return -1. Example Test Case 1: Input: s = “leetcode” Output: 0 Test Case 2: Input: s = “aabb” Output: -1 Explanation …

Read more

Invert Binary Tree LeetCode Solution

Problem Statement: Invert Binary Tree LeetCode Solution – In this question, Given a root of any binary tree, the solution is required to invert the binary tree meaning the left tree should become the right tree and vice versa.   Explanation We can ask ourselves which tree traversal would be …

Read more

Closest Binary Search Tree Value Leetcode Solution

Problem Statement : Closest Binary Search Tree Value Leetcode Solution – Given the root of a binary search tree and a target value, return the value in the BST that is closest to the target. Example : Example 1 Input: root = [4,2,5,1,3], target = 3.714286 Output: 4 Example 2 Input: root = [1], target …

Read more

Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution

Problem Statement Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution – Given two n x n binary matrices mat and target, return true if it is possible to make mat equal to target by rotating mat in 90-degree increments, or false otherwise. Examples Input: mat = [[0,1],[1,0]], target = [[1,0],[0,1]] Output: true Explanation: We can rotate mat 90 degrees clockwise to make mat equal …

Read more

Reformat Date LeetCode Solution

Problem Statement Reformat Date LeetCode Solution – Given a date string in the form Day Month Year, where: Day is in the set {“1st”, “2nd”, “3rd”, “4th”, …, “30th”, “31st”}. Month is in the set {“Jan”, “Feb”, “Mar”, “Apr”, “May”, “Jun”, “Jul”, “Aug”, “Sep”, “Oct”, “Nov”, “Dec”}. Year is in the range [1900, 2100]. Convert the date string …

Read more

Sort Array by Increasing Frequency Leetcode Solution

Problem Statement The Sort Array by Increasing Frequency LeetCode Solution – “Sort Array by Increasing Frequency” states that you’re given an array of integers, sort the array in increasing order based on the frequency of the values. Two or more values have the same frequency, we need to sort them …

Read more

Longest Nice Substring LeetCode Solution

Problem Statement : Longest Nice Substring LeetCode Solution – A string s is nice if, for every letter of the alphabet that s contains, it appears both in uppercase and lowercase. For example, “abABB” is nice because ‘A’ and ‘a’ appear, and ‘B’ and ‘b’ appear. However, “abA” is not because ‘b’ appears, but ‘B’ does not. Given a string s, return the longest substring of s that is nice. If there are multiple, return the substring of …

Read more

Translate »