Search in Rotated Sorted Array

Problem Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., [0, 1, 2, 4, 5, 6, 7] might become [4, 5, 6, 7, 0, 1, 2]). You are given a target value to search. If found in the array return its index, otherwise return -1. You may assume no duplicate exists in the array. Follow up: what if duplicates are allowed? ...

Non-decreasing Array Problem

Problem Given an array nums with n integers, your task is to check if it could become non-decreasing by modifying at most one element. We define an array is non-decreasing if nums[i] <= nums[i + 1] holds for every i (0-based) such that (0 <= i <= n - 2). Examples Example 1: Input: nums = [4,2,3] Output: true Explanation: You could modify the first 4 to 1 to get a non-decreasing array. ...

Best Time To Buy And Sell Stock 1 - only one transaction

Problem You are given an array prices where prices[i] is the price of a given stock on the ith day. You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock. Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0. OR ...

Merge Two Sorted Arrays

Problem Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may assume that A has enough space to hold additional elements from B. The number of elements initialized in A and B are m and n respectively. Similar Problem You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively. ...

Squares of a Sorted array Problem

Problem Given an array of numbers sorted in increasing order, return a new array containing squares of all the numbers of the input array sorted in increasing order. Examples Example 1: Input: a[] = [-5, -2, -1, 0, 4, 6] Output: [0, 1, 4, 16, 25, 36] Explanation: After squaring, the array becomes [25, 4, 1, 0, 16, 36]. After sorting, it becomes [0, 1, 4, 16, 25, 36]. ...

Regular Expression Matching Problem

Problem Given an input string s and a pattern p, implement regular expression matching with support for '.' and '*' where: '.' Matches any single character. '*' Matches zero or more of the preceding element. The matching should cover the entire input string (not partial). Examples Some examples: isMatch("aa","a") ? false isMatch("aa","a.") ? true isMatch("aaa","ab*") ? false isMatch("aa", ".*") ? true isMatch("aa", "a*") ? true isMatch("ab", ".*") ? true isMatch("aabaa", "a*b.*") ? false ...

Add Two Numbers represented as Linked List in Reversed Order

Problem You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 itself. Examples Example 1: (2 -> 4 -> 3) + (5 -> 6 -> 4) => 7 -> 0 -> 8 Input: l1 = [2,4,3], l2 = [5,6,4] Output: [7,0,8] Explanation: 342 + 465 = 807 ...

Shift 2D Grid Problem

Problem Given a 2D grid of size m x n and an integer k. You need to shift the grid k times. In one shift operation: Element at grid[i][j] moves to grid[i][j + 1]. Element at grid[i][n - 1] moves to grid[i + 1][0]. Element at grid[m - 1][n - 1] moves to grid[0][0]. Return the 2D grid after applying shift operation k times. Examples Example 1: ...

Isomorphic Strings Problem

Problem Given two strings s and t, determine if they are isomorphic. Definition Two strings s and t are isomorphic if the characters in s can be replaced to get t. All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character, but a character may map to itself. Example Example 1: ...

Valid Palindrome 2 Problem

Problem Given a string s, return true if the s can be palindrome after deleting at most one character from it. Examples Example 1: Input: s = "aba" Output: true Example 2: Input: s = "abca" Output: true Explanation: You could delete the character 'c'. ...

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