Single Number 2 - All elements except one occur thrice

Problem Given an integer array nums where every element appears three times except for one, which appears exactly once. Find the single element and return it. You must implement a solution with a linear runtime complexity and use only constant extra space. Examples Example 1: Input : nums = [1, 2, 4, 3, 3, 2, 2, 3, 1, 1] Output : 4 ...

Divide Two Integers Problem

Problem Given two integers dividend and divisor, divide two integers without using multiplication, division, and mod operator. The integer division should truncate toward zero, which means losing its fractional part. For example, 8.345 would be truncated to 8, and -2.7335 would be truncated to -2. Return the quotient after dividing dividend by divisor. Note: Assume we are dealing with an environment that could only store integers within the 32-bit signed integer range: [−2^31, 2^31 − 1]. For this problem, if the quotient is strictly greater than 2^31 - 1, then return 2^31 - 1, and if the quotient is strictly less than -2^31, then return -2^31. ...

Dutch National Flag DNF problem

Problem Given an array nums with n objects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white, and blue. We will use the integers 0, 1, and 2 to represent the color red, white, and blue, respectively. You must solve this problem without using the library’s sort function. By the way this is Dutch National Flag - 🇳🇱. ...

Longest Increasing Subsequence LIS Problem

Problem Given an unsorted array of integers, find the length of longest increasing subsequence. Examples Example 1: Input: A = [10,9,2,5,3,7,101,18] Output: 4 Explanation: The longest increasing subsequence is [2,3,7,101], therefore the length is 4. ...

Count Complete Tree Nodes Problem

Problem Given the root of a complete binary tree, return the number of the nodes in the tree. Definition and Properties of Complete Binary Tree Complete Binary Tree Examples Example 1: 1 / \ 2 3 / \ / 4 5 6 ...

Count Univalue Subtrees Problem

Problem Given a binary tree, write a program to count the number of Single Valued Subtrees. A Single Valued Subtree is one in which all the nodes have same value. Expected time complexity is O(n). Example Examples 1: 5 / \ 1 5 / \ \ 5 5 5 ...

Valid Parentheses Problem

Problem 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. Examples Example 1: ...

What happens when you type an URL in the browser and press enter

The diagram below illustrates the steps. --- title: Refreshing an Expired Access Token --- sequenceDiagram autonumber actor User participant Browser participant DNSCache participant DNSResolver participant Server User->>Browser: enters an URL in the browser say https://k5kc.com/cs/algorithms/2sum-problem Browser->>DNSCache: Look up IP Browser->>DNSResolver: Send DNS Query (If not found in dns cache) DNSResolver-->>Browser: Resolve URL to IP Address Browser->>Server: Establishes TCP connection Browser->>Server: Send HTTP/HTTPS Request Server-->>Browser: Process Request and Send Response Browser->>Browser: Render HTML Content Browser->>Browser: Fetch and Execute CSS/JavaScript Browser-->>User: Page Fully Loads User-->>Browser: Possible Interactions ...

Climbing Stairs Problem 1 - Take atmost 2 Steps

Problem You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? OR There are n stairs, a person standing at the bottom wants to reach the top. The person can climb either 1 stair or 2 stairs at a time. Count the number of ways, the person can reach the top. ...

Evaluation of Arithmetic Expression Tree

Problem Given a simple expression tree, consisting of basic binary operators i.e., + , – , * and / and some integers, evaluate the expression tree. Examples Example 1: graph TD; A(+) --- B(*) & C("-") B --- D(5) & E(4) C --- F(100) & G(20) Input: root = ["+", "*", "-", "5", "4", "100", "20"] Output: 100 ...

This site uses cookies to improve your experience on our website. By using and continuing to navigate this website, you accept this. Privacy Policy