Insert Delete GetRandom O(1) Leetcode Solution

Problem Statement The Insert Delete GetRandom O(1) LeetCode Solution – “Insert Delete GetRandom O(1)” asks you to implement these four functions in O(1) time complexity. insert(val): Insert the val into the randomized set and return true if the element is initially absent in the set. It returns false when the …

Read more

LRU Cache Leetcode Solution

Problem Statement The LRU Cache LeetCode Solution – “LRU Cache” asks you to design a data structure that follows Least Recently Used (LRU) Cache We need to implement LRUCache class that has the following functions: LRUCache(int capacity): Initializes the LRU cache with positive size capacity. int get(int key): Return the value …

Read more

Longest Common Prefix Leetcode Solution

Problem Statement The Longest Common Prefix LeetCode Solution – “Longest Common Prefix” states that given an array of strings. We need to find the longest common prefix among these strings. If there doesn’t exist any prefix, return an empty string. Example: Input: strs = [“flower”,”flow”,”flight”] Output: “fl” Explanation: “fl” is the longest …

Read more

Trapping Rain Water Leetcode Solution

Problem Statement The Trapping Rain Water LeetCode Solution – “Trapping Rain Water” states that given an array of heights which represents an elevation map where the width of each bar is 1. We need to find the amount of water trapped after rain. Example: Input: height = [0,1,0,2,1,0,1,3,2,1,2,1] Output: 6 Explanation: Check …

Read more

Maximum Difference Between Increasing Elements LeetCode Solution

Problem Statement Maximum Difference Between Increasing Elements LeetCode Solution – Given a 0-indexed integer array nums of size n, find the maximum difference between nums[i] and nums[j] (i.e., nums[j] – nums[i]), such that 0 <= i < j < n and nums[i] < nums[j]. Return the maximum difference. If no such i and j exists, return -1. Examples & Explanations Example 1: Input: nums = [7,1,5,4] Output: 4 Explanation: The maximum difference occurs …

Read more

Valid Parentheses Leetcode Solution

Problem Statement The Valid Parentheses LeetCode Solution – “Valid Parentheses” states that you’re given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[‘ and ‘]’. We need to determine whether the input string is a valid string or not. A string is said to be a valid string if open brackets must be closed …

Read more

Find Median from Data Stream LeetCode Solution

Problem Statement Find Median from Data Stream LeetCode Solution – The median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value and the median is the mean of the two middle values. For example, for arr = [2,3,4], the median …

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

Robot Bounded In Circle LeetCode Solution

Problem Statement Robot Bounded In Circle LeetCode Solution – On an infinite plane, a robot initially stands at (0, 0) and faces north. Note that: The north direction is the positive direction of the y-axis. The south direction is the negative direction of the y-axis. The east direction is the positive direction of the x-axis. The west direction is the …

Read more

Translate »