Author: devangini123

Problem Statement: Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have to wait after the ith day to get a warmer temperature. If there is no future day for which this is possible, keep answer[i] == 0 instead. Examples: Example 1: Input: temperatures = [73,74,75,71,69,72,76,73] Output: [1,1,4,2,1,1,0,0] Example 2: Input: temperatures = [30,40,50,60] Output: [1,1,1,0] Example 2: Input: temperatures = [30,60,90] Output: [1,1,0] Constraints: 1 = 69) → pop 4 → stack = [6, 5] → top = 5 → arr[3] < arr[5] (71 <…

Read More

Problem Statement: The next greater element of some element x in an array is the first greater element that is to the right of x in the same array. You are given two distinct 0-indexed integer arrays nums1 and nums2, where nums1 is a subset of nums2. For each 0

Read More

Problem Statement: You are given an array of strings tokens that represents an arithmetic expression in a Reverse Polish Notation. Evaluate the expression. Return an integer that represents the value of the expression. Note that: The valid operators are ‘+’, ‘-‘, ‘*’, and ‘/’ . Each operand may be an integer or another expression. The division between two integers always truncates toward zero. There will not be any division by zero. The input represents a valid arithmetic expression in a reverse polish notation. The answer and all the intermediate calculations can be represented in a 32-bit integer. Examples: Example 1:…

Read More

Problem Statement: A valid parentheses string is either empty “”, “(” + A + “)”, or A + B, where A and B are valid parentheses strings, and + represents string concatenation. For example, “”, “()”, “(())()”, and “(()(()))” are all valid parentheses strings. A valid parentheses string s is primitive if it is nonempty, and there does not exist a way to split it into s = A + B, with A and B nonempty valid parentheses strings. Given a valid parentheses string s, consider its primitive decomposition: s = P1 + P2 + … + Pk, where Pi…

Read More

Problem Statement: A valid parentheses string is either empty “”, “(” + A + “)”, or A + B, where A and B are valid parentheses strings, and + represents string concatenation. For example, “”, “()”, “(())()”, and “(()(()))” are all valid parentheses strings. A valid parentheses string s is primitive if it is nonempty, and there does not exist a way to split it into s = A + B, with A and B nonempty valid parentheses strings. Given a valid parentheses string s, consider its primitive decomposition: s = P1 + P2 + … + Pk, where Pi…

Read More

🌙 Problem Statement: Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. Implement the MinStack class: MinStack()initializes the stack object. void push(int val)pushes the element val onto the stack. void pop()removes the element on the top of the stack. int top()gets the top element of the stack. int getMin()retrieves the minimum element in the stack. You must implement a solution with O(1) time complexity for each function. Examples: Example 1: Input: [“MinStack”,”push”,”push”,”push”,”getMin”,”pop”,”top”,”getMin”] [[],[-2],[0],[-3],[],[],[],[]] Output:[null,null,null,null,-3,null,0,-2] Explanation MinStack minStack = new MinStack(); minStack.push(-2); minStack.push(0); minStack.push(-3); minStack.getMin(); // return -3 minStack.pop(); minStack.top(); // return 0 minStack.getMin();…

Read More

🌙 Problem Statement: Given a string s containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[‘ and ‘]’, determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. Every close bracket has a corresponding open bracket of the same type. Example 1: Input: s = “()” Output: true Example 2: Input: s = “()[]{}” Output: true Example 3: Input: s = “(]” Output: false Example 4: Input: s = “([])” Output: true Example 5: Input: s =…

Read More

🌙 Problem Statement: Implement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue (push, peek, pop, and empty). Implement the MyQueue class: void push(int x)Pushes element x to the back of the queue. int pop()Removes the element from the front of the queue and returns it. int peek()Returns the element at the front of the queue. boolean empty()Returns true if the queue is empty, false otherwise. Notes You must use only standard operations of a stack, which means only push to top, peek/pop from top, size…

Read More

🌙 Problem Statement: Implement a last-in-first-out (LIFO) stack using only two queues. The implemented stack should support all the functions of a normal stack (push, top, pop, and empty). Implement the MyStack class: void push(int x)Pushes element x to the top of the stack. int pop()Removes the element on the top of the stack and returns it.. int top()Returns the element on the top of the stack. boolean empty()Returns true if the stack is empty, false otherwise. Notes You must use only standard operations of a queue, which means that only push to back, peek/pop from front, size and is…

Read More

🌙 Problem Statement: Implement a last-in-first-out (LIFO) stack using only two queues. The implemented stack should support all the functions of a normal stack (push, top, pop, and empty). Implement the MyStack class: void push(int x)Pushes element x to the top of the stack. int pop()Removes the element on the top of the stack and returns it.. int top()Returns the element on the top of the stack. boolean empty()Returns true if the stack is empty, false otherwise. Notes You must use only standard operations of a queue, which means that only push to back, peek/pop from front, size and is…

Read More