Spiral Matrix 1 - Return

Problem Given an m x n matrix, return all elements of the matrix in spiral order. Examples Example 1: Input: matrix = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] Output: [1,2,3,6,9,8,7,4,5] Example 2: Input: matrix = [ [1,2,3,4],[5,6,7,8],[9,10,11,12] ] Output: [1,2,3,4,8,12,11,10,9,5,6,7] ...

Square root of an integer Problem

Problem Implement int sqrt(int x). OR Compute and return the square root of x. OR If x is not a perfect square, return floor(sqrt(x)) OR floor(√n) OR Given a non-negative integer x, compute and return the square root of x. Since the return type is an integer, the decimal digits are truncated, and only the integer part of the result is returned. ...

Strobogrammatic Number 1 - Check if strobogrammatic

Problem A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down). Write a function to determine if a number is strobogrammatic. The number is represented as a string. Examples Example 1: Input: "69" Output: true Example 2: Input: "88" Output: true ...

Strobogrammatic Number 2 - Generate for length n

Problem A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down). Find all strobogrammatic numbers that are of length = n. Examples Example 1: Input: n = 2 Output: ["11","69","88","96"] Similar Problems Strobogrammatic Number 1 - Check if strobogrammatic ...

Strobogrammatic Number 3 - Count in Range

Problem A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down). Write a function to count the total strobogrammatic numbers that exist in the range of low <= num <= high. Examples Example 1: Input: low = "50", high = "100" Output: 3 Explanation: 69, 88, and 96 are three strobogrammatic numbers. ...

Sudoku Solver Problem

Problem Solve a well-posed sudoku puzzle. What Sudoku is a popular game that many of you are familiar with. The main idea of the game is to fill a grid with only the numbers from 1 to 9, while ensuring that each row and each column as well as each sub-grid of 9 elements does not contain duplicate numbers. Examples Example 1: ...

Swap Nodes in Pairs Problem

Problem Given a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list’s nodes (i.e., only nodes themselves may be changed.) Examples Example 1: --- title: Input --- graph LR; 1 --> 2:::focus --> 3 -->4:::focus classDef focus fill:#f96 --- title: Output --- graph LR; 2:::focus --> 1 --> 4:::focus -->3 classDef focus fill:#f96 ...

Valid Sudoku Problem

Problem Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules: Each row must contain the digits 1-9 without repetition. Each column must contain the digits 1-9 without repetition. Each of the nine 3 x 3 sub-boxes of the grid must contain the digits 1-9 without repetition. Note: A Sudoku board (partially filled) could be valid but is not necessarily solvable. Only the filled cells need to be validated according to the mentioned rules. The Sudoku board could be partially filled, where empty cells are filled with the character ‘.’. ...

Validate Binary Search Tree Problem

Problem Given the root of a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node’s key. The right subtree of a node contains only nodes with keys greater than the node’s key. Both the left and right subtrees must also be binary search trees. Examples Example 1: ...

Implement Rand10() Using Rand7()

Problem Given the API rand7() that generates a uniform random integer in the range [1, 7], write a function rand10() that generates a uniform random integer in the range [1, 10]. You can only call the API rand7(), and you shouldn’t call any other API. Please do not use a language’s built-in random API. Each test case will have one internal argument n, the number of times that your implemented function rand10() will be called while testing. Note that this is not an argument passed to rand10(). ...

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