leetcode-solution

First Bad Version | Leetcode | Solution

Hi, In this post we will be discussing the first bad version problem present on LeetCode Video Solution Problem Statement You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the previous …

First Bad Version | Leetcode | Solution Read More »

Divide Two Integers | Leet Code

Given two integers dividend and divisor, divide them and output the quotient, without using multiplication, division and mode operator. Note: Both dividend and divisor will be 32-bit signed integers. The divisor will never be 0. Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231,  231 − 1]. For …

Divide Two Integers | Leet Code Read More »

Remove Kth Node From End From Linked List | LeetCode

Given a linked list with N nodes, remove the kth node from end and return its head. Bonus: Do it in one iteration. Solution To remove the kth node from the linked list, first step is traversing to the (k-1)th node in the linked list. After that, we just need to rewire the pointers and …

Remove Kth Node From End From Linked List | LeetCode Read More »

Deleting a node in linked list

Delete a node in linked list Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Example: Input: head = [1,2,3,4], node = 2 Output: [1,3,4] Explanation: You are given the second node with value 2, the linked list should become 1 -> 3 …

Deleting a node in linked list Read More »

Remove Linked List Elements

Remove Linked List Elements Companies: Pure Storage, Bloomberg, Google, Capital one Remove all elements from a linked list of integers that have value val. Example: Input: 1->2->3->2->4->5 val = 2 Output: 1->3->4->5 Solution: This problems looks simple as long as we have to delete the nodes from the middle. But when it comes to deletion …

Remove Linked List Elements Read More »

Remove all adjacent duplicates in string

Remove All Adjacent Duplicates In String Link Companies: Bloomberg, Facebook, Google, Oracle Given a string S of lowercase letters, a duplicate removal consists of choosing two adjacent and equal letters, and removing them. We repeatedly make duplicate removals on S until we no longer can. Return the final string after all such duplicate removals have …

Remove all adjacent duplicates in string Read More »

Baseball Game

Baseball Game Link Companies: Amazon You’re now a baseball game point recorder. Given a list of strings, each string can be one of the 4 following types: Integer (one round’s score): Directly represents the number of points you get in this round. “+” (one round’s score): Represents that the points you get in this round …

Baseball Game Read More »

Implement Queue Using Stacks

Implement Queue using Stacks Link Implement the following operations of a queue using stacks. push(x) — Push element x to the back of queue. pop() — Removes the element from in front of queue. peek() — Get the front element. empty() — Return whether the queue is empty. Example: MyQueue queue = new MyQueue(); queue.push(3); …

Implement Queue Using Stacks Read More »

Implement Stack Using Queues

Implement Stack using Queues Link Companies: Microsoft Implement the following operations of a stack using queues. push(x) — Push element x onto stack. pop() — Removes the element on top of the stack. top() — Get the top element. empty() — Return whether the stack is empty. Example: MyStack stack = new MyStack(); stack.push(6); stack.push(3); …

Implement Stack Using Queues Read More »

Min Stack

Min Stack Link Companies: Amazon, Netflix, Google, Bloomberg, Microsoft, Adobe, Oracle, Apple. Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) — Push element x onto stack. pop() — Removes the element on top of the stack. top() — Get the top element. getMin() — Retrieve the …

Min Stack Read More »

Scroll to Top
[gravityforms id="5" description="false" titla="false" ajax="true"]