Shawn's blog
CERTIFICATEMY HUMAN GRAPHABOUTARCHIVESCATEGORIESHOMETAGS
  • WSL2 Network

    Oct 26, 2022 About 1 min

    How to access server which is hosted on WSL2 ? Use proxy to forward connection from win10 to wsl2. [powershell] > netsh interface portproxy show all # listen address/port -> windows 10 ip/port # connect address/port -> wsl2 ip/port [powershell] > netsh interface portproxy add v4tov4 listenaddress=0.0.0... Read More

    #Linux#WSL2
  • [HTB - Starting Point] Three

    Oct 18, 2022 About 2 mins

    Task 1 Q : How many TCP ports are open? [host] # nmap -sVC -p- --open <target_ip> -oA Three_full_scan A : 2 Task 2 Q : What is the domain of the email address provided in the “Contact” section of the website? A : thetoppers.htb Task 3 Q : In the absence of a DNS server, which Linux file can we use to resolve hostnames to IP addresses in... Read More

    #HTB#Starting Point
  • [HTB - Starting Point] Archetype

    Oct 18, 2022 About 2 mins

    Task 1 Q : Which TCP port is hosting a database server? [host] # nmap -sVC -p- --open -oA Archetype_full_scan <target_ip> A : 1433 Task 2 Q : What is the name of the non-Administrative share available over SMB? [host] # smbclient -N -L <target_ip> A : backups Task 3 Q : What is the password identified in the file on the SMB share... Read More

    #HTB#Starting Point
  • [HTB - Starting Point] Sequel

    Oct 16, 2022 About 1 min

    Task 1 Q : What does the acronym SQL stand for? A : Structured Query Language Task 2 Q : During our scan, which port running mysql do we find? [host] # nmap -sVC --open -oA Sequel_init_scan <target_ip> A : 3306 Task 3 Q : What community-developed MySQL version is the target running? A : MariaDB Task 4 Q : What switch do we need to use ... Read More

    #HTB#Starting Point
  • [HTB - Starting Point] Responder

    Oct 16, 2022 About 2 mins

    Task 1 Q : When visiting the web service using the IP address, what is the domain that we are being redirected to? A : unika.htb Note : In order to view the website, add unika.htb domain into hosts file. Task 2 Q : Which scripting language is being used on the server to generate webpages? A : PHP Note : Use wappalyzer Task 3 Q : What is the na... Read More

    #HTB#Starting Point
  • [HTB - Starting Point] Crocodile

    Oct 16, 2022 About 1 min

    Task 1 Q : What nmap scanning switch employs the use of default scripts during a scan? A : -sC Task 2 Q : What service version is found to be running on port 21? [host] # nmap -sCV --open -oA Crocodile_init_scan <target_ip> A : vsftpd 3.0.3 Task 3 Q : What FTP code is returned to us for the “Anonymous FTP login allowed” message? [host] ... Read More

    #HTB#Starting Point
  • [HTB - Starting Point] Appointment

    Oct 16, 2022 About 1 min

    Task 1 Q : What does the acronym SQL stand for? A : Structured Query Language Task 2 Q : What is one of the most common type of SQL vulnerabilities? A : sql injection Task 3 Q : What does PII stand for? A : personally identifiable information Task 4 Q : What does the OWASP Top 10 list name the classification for this vulnerability? A : A03:20... Read More

    #HTB#Starting Point
  • [HTB - Starting Point] Redeemer

    Oct 12, 2022 About 1 min

    Task 1 Q : Which TCP port is open on the machine? [host] # nmap --open -p- -sV <target_ip> -oA Redeemer_full_scan A : 6379 Task 2 Q : Which service is running on the port that is open on the machine? A : redis Task 3 Q : What type of database is Redis? Choose from the following options: (i) In-memory Database, (ii) Traditional Database ... Read More

    #HTB#Starting Point
  • [HTB - Starting Point] Fawn

    Oct 12, 2022 About 1 min

    Task 1 Q : What does the 3-letter acronym FTP stand for? A : File Transfer Protocol Task 2 Q : Which port does the FTP service listen on usually? A : 21 Task 3 Q : What acronym is used for the secure version of FTP? A : SFTP Task 4 Q : What is the command we can use to send an ICMP echo request to test our connection to the target? A : ping ... Read More

    #HTB#Starting Point
  • [HTB - Starting Point] Dancing

    Oct 12, 2022 About 1 min

    Task 1 Q : What does the 3-letter acronym SMB stand for? A : Server Message Block Task 2 Q : What port does SMB use to operate at? A : 445 Task 3 Q : What is the service name for port 445 that came up in our Nmap scan? [host] # nmap -sV --open <target_ip> -oA Dancing_init_scan A : microsoft-ds Task 4 Q : What is the ‘flag’ or ‘switch’ ... Read More

    #HTB#Starting Point
  • [HTB - Starting Point] Meow

    Oct 02, 2022 About 1 min

    Task 1 Q : What does the acronym VM stand for? A : Virtual Machine Task 2 Q : What tool do we use to interact with the operating system in order to issue commands via the command line, such as the one to start our VPN connection? It’s also known as a console or shell. A : Terminal Task 3 Q : What service do we use to form our VPN connection in... Read More

    #HTB#Starting Point
  • Linux Device Driver 3rd edition - CH5 recap

    Mar 11, 2022 About 23 mins

    Concurrency and Race Conditions what is concurrency? what happens when the system tries to do more than one thing a once. concurrency is one of the core problems in operating system. concurrency-related bugs are some of the easiest to create and some of hardest to find. Pitfalls in scull // write logic if (!dp... Read More

    #LDD3
  • sg3 utils

    Feb 18, 2022 About 29 mins

    reference: The sg3_utils package Introduction Send SCSI commands to devices on transports traditionally associated with SCSI. Fibre Channel (FCP) Serial Attached SCSI (SAS) SCSI Parallel Interface (SPI) ATAPI cd/dvd drivers and SATA disks connect via a translation layer or a bridge that use SCSI command sets. ... Read More

    #sg driver
  • Linux Device Driver 3rd edition - CH4 recap

    Feb 08, 2022 About 30 mins

    Debugging Techniques Debugging Support in the Kernel Configuration options in kernel CONFIG_DEBUG_KERNEL Just make other debugging options available. CONFIG_DEBUG_SLAB Set allocated memory to 0xa5. Set freed memory to 0x6b. CONFIG_DEBUG_PAGE... Read More

    #LDD3
  • Basic scull build from scratch

    Feb 07, 2022 About 22 mins

    Flowchart scull.c #include <linux/init.h> /* essential */ #include <linux/module.h> /* essential */ #include <linux/fs.h> /* file system */ #include <linux/types.h> /* dev_t */ #include <linux/errno.h> /* error code */ #include <linux/cdev.h> /* char device */ #include <linux/slab.h> /* kmalloc, k... Read More

    #LDD3
  • Linux Device Driver 3rd edition - CH3 recap

    Jan 28, 2022 About 17 mins

    Char Drivers Take scull (Simple Character Utility for Loading Localities) for example. scull is not hardware dependent, it is a device which acts on some memory allocated from the kernel. scull is used to demonstrate the interface between the kernel and char drivers and allow the user to run some tests. The Design of scull The firs... Read More

    #LDD3
  • Linux Device Driver 3rd edition - CH2 recap

    Jan 26, 2022 About 9 mins

    Building and Running Modules Setting Up Your Test System You can get latest mainline kernel from kernel.org to setup your test environment. [Tip] Prepare a “sacrificial” environment to test your new code, so that it won’t ruin your machine. (The possibility of bugs is always present) The Hello World Module #include <linux/init.h> #inclu... Read More

    #LDD3
  • oh-my-zsh Setup

    Jan 26, 2022 About 1 min

    Result (using Tabby terminal) Setup steps update OS $ sudo apt-get update $ sudo apt-get upgrade install zsh $ sudo apt-get install -y zsh // check zsh is installed. $ cat /etc/shells // change default shell $ chsh -s $(which zsh) install oh-my-zsh $ sh -c "$(wget -O- https://raw.githubusercontent.c... Read More

    #zsh#oh-my-zsh#terminal
  • Linux Device Driver 3rd edition - CH1 recap

    Jan 25, 2022 About 1 min

    An Introduction to Device Drivers Role of Device driver Black boxes between user(applications) and hardware. Provide mechanism (what capabilities are to be provided) instead of policy(how those capabilities can be used) Splitting the Kernel Process management Memory management Filesystems Device control Networking Load... Read More

    #LDD3
  • WSL git clone error

    Jan 25, 2022 About 1 min

    Git clone with Ubuntu WSL, and an error occured. error: chmod on /mnt/d/nshawn4675.github.io/.git/config.lock failed: Operation not permitted Because /mnt/d is a NTFS partition so that chmod doesn’t work. Steps to solve this problem: Launch Ubuntu WSL Create / Modify WSL conf file $ sudo vi /etc/wsl.conf [automount] opt... Read More

    #WSL#git
  • Enlarge swap space

    Jan 20, 2022 About 1 min

    Enlarge swap space to 16GB $ sudo swapoff /swapfile $ sudo rm /swapfile $ sudo dd if=/dev/zero of=/swapfile bs=1M count=16384 $ sudo chmod 600 /swapfile $ sudo mkswap /swapfile $ sudo swapon /swapfile // check swap $ cat /proc/swaps Read More

    #Linux#Ubuntu
  • Windows10 & VirtualBox Ubuntu20.04 - shared folder

    Jan 15, 2022 About 1 min

    Add a shared folder on host side. virtualbox → your machine (powered off) → settings → Shared Folders → Add new shared folder → select “Folder Path” on win10 → enter “Folder Name” = “win10_shared” → unchecked “Read-only” and “Auto-mount”. Install VBoxLinuxAdditions on guest side. Turn on machine → Devices → Insert Guest Addtions CD Image… // ... Read More

    #Windows10#VirtualBox#Ubuntu
  • [LeetCode April Challange] Day 21 - Triangle

    Apr 21, 2021 About 1 min

    Given a triangle array, return the minimum path sum from top to bottom. For each step, you may move to an adjacent number of the row below. More formally, if you are on index i on the current row, you may move to either index i or index i + 1 on the next row. Example 1: Input: triangle = [[2],[3,4],[6,5,7],[4,1,8,3]] Output: 11 Explanation: T... Read More

    #Medium#Array#Dynamic Programming#Amazon#Bloomberg#C++
  • [LeetCode April Challange] Day 20 - N-ary Tree Preorder Traversal

    Apr 20, 2021 About 1 min

    Given the root of an n-ary tree, return the preorder traversal of its nodes’ values. Nary-Tree input serialization is represented in their level order traversal. Each group of children is separated by the null value (See examples) Example 1: Input: root = [1,null,3,2,4,null,5,6] Output: [1,3,5,6,2,4] Example 2: Input: root = [1,null,2,... Read More

    #Easy#Stack#Tree#Depth-First Search#C++
  • [LeetCode April Challange] Day 18 - Remove Nth Node From End of List

    Apr 18, 2021 About 1 min

    Given the head of a linked list, remove the n-th node from the end of the list and return its head. Follow up: Could you do this in one pass? Example 1: Input: head = [1,2,3,4,5], n = 2 Output: [1,2,3,5] Example 2: Input: head = [1], n = 1 Output: [] Example 3: Input: head = [1,2], n = 1 Output: [1] Constraints: The number of no... Read More

    #Medium#Linked List#Two Pointers#Facebook#Amazon#Apple#Bloomberg#Microsoft#C++
  • [LeetCode April Challange] Day 15 - Fibonacci Number

    Apr 15, 2021 About 1 min

    The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. That is, F(0) = 0, F(1) = 1 F(n) = F(n - 1) + F(n - 2), for n > 1. Given n, calculate F(n). Example 1: Input: n = 2 Output: 1 Explanation: F(2) = F(1) + F(0) = 1 +... Read More

    #Easy#Math#Dynamic Programming#Recursion#Memoization#JPMorgan#Amazon#Google#Apple#Facebook#C++
  • [LeetCode April Challange] Day 14 - Partition List

    Apr 14, 2021 About 1 min

    Given the head of a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the original relative order of the nodes in each of the two partitions. Example 1: Input: head = [1,4,3,2,5,2], x = 3 Output: [1,2,2,4,3,5] Example 2: Input: head = [2,1], x = 2 Out... Read More

    #Medium#Linked List#Two Pointers#Microsoft#Amazon#Apple#Facebook#C++
  • [LeetCode April Challange] Day 13 - Flatten Nested List Iterator

    Apr 13, 2021 About 2 mins

    You are given a nested list of integers nestedList. Each element is either an integer or a list whose elements may also be integers or other lists. Implement an iterator to flatten it. Implement the NestedIterator class: NestedIterator(List<NestedInteger> nestedList) Initializes the iterator with the nested list nestedList. int next... Read More

    #Medium#Stack#Tree#Depth-First Search#Design#Queue#Iterator#Facebook#Apple#Amazon#Airbnb#LinkedIn#Bloomberg#Oracle#C++
  • [LeetCode April Challange] Day 12 - Beautiful Arrangement II

    Apr 12, 2021 About 1 min

    Given two integers n and k, you need to construct a list which contains n different positive integers ranging from 1 to n and obeys the following requirement: Suppose this list is [a1, a2, a3, … , an], then the list [|a1 - a2|, |a2 - a3|, |a3 - a4|, … , |an-1 - an|] has exactly k distinct integers. If there are multiple answers, print any of th... Read More

    #Medium#Array#Math#Google#C++
  • [LeetCode April Challange] Day 11 - Deepest Leaves Sum

    Apr 11, 2021 About 1 min

    Given the root of a binary tree, return the sum of values of its deepest leaves. Example 1: Input: root = [1,2,3,4,5,null,6,7,null,null,null,null,8] Output: 15 Example 2: Input: root = [6,7,8,2,7,1,3,9,null,1,4,null,null,null,5] Output: 19 Constraints: The number of nodes in the tree is in the range [1, 10^4]. 1 <= Node.va... Read More

    #Medium#Tree#Depth-First Search#Breadth-First Search#Binary Tree#Google#C++
  • [LeetCode April Challange] Day 10 - Longest Increasing Path in a Matrix

    Apr 10, 2021 About 1 min

    Given an m x n</fotn> integers matrix, return *the length of the longest increasing path in* matrix. From each cell, you can either move in four directions: left, right, up, or down. You may not move diagonally or move outside the boundary (i.e., wrap-around is not allowed). Example 1: Input: matrix = [[9,9,4],[6,6,8],[2,1,1]] Output:... Read More

    #Hard#Dynamic Programming#Depth-First Search#Breadth-First Search#Graph#Topological Sort#Memoization#Google#Facebook#Bloomberg#Amazon#ByteDance#DoorDash#C++
  • Inorder Successor in BST

    Apr 10, 2021 About 2 mins

    Given the root of a binary search tree and a node p in it, return the in-order successor of that node in the BST. If the given node has no in-order successor in the tree, return null. The successor of a node p is the node with the smallest key greater than p.val. Example 1: Input: root = [2,1,3], p = 1 Output: 2 Explanation: 1's in-order su... Read More

    #Medium#Tree#Amazon#Microsoft#C++
  • [LeetCode April Challange] Day 09 - Verifying an Alien Dictionary

    Apr 09, 2021 About 1 min

    In an alien language, surprisingly they also use english lowercase letters, but possibly in a different order. The order of the alphabet is some permutation of lowercase letters. Given a sequence of words written in the alien language, and the order of the alphabet, return true if and only if the given words are sorted lexicographicaly in this ... Read More

    #Easy#Array#Hash Table#String#Facebook#Walmart Labs#Amazon#C++
  • [LeetCode April Challange] Day 08 - Letter Combinations of a Phone Number

    Apr 08, 2021 About 1 min

    Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. Return the answer in any order. A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters. Example 1: Input: digits = "23" Output: ["ad","ae","af","bd"... Read More

    #Medium#Hash Table#String#Backtracking#Amazon#Microsoft#Twilio#Facebook#Capital One#eBay#Google#Uber#Apple#Oracle#JPMorgan#Morgan Stanley#Tesla#Qualtrics#Samsung#C++
  • Largest Unique Number

    Apr 07, 2021 About 1 min

    Given an array of integers A, return the largest integer that only occurs once. If no integer occurs once, return -1. Example 1: Input: [5,7,3,9,4,9,8,3,1] Output: 8 Explanation: The maximum integer in the array is 9 but it is repeated. The number 8 occurs only once, so it's the answer. Example 2: Input: [9,9,8,8] Output: -1 Explanation: ... Read More

    #Easy#Array#Hash Table#Amazon#C++
  • [LeetCode April Challange] Day 07 - Determine if String Halves Are Alike

    Apr 07, 2021 About 1 min

    You are given a string s of even length. Split this string into two halves of equal lengths, and let a be the first half and b be the second half. Two strings are alike if they have the same number of vowels ('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'). Notice that s contains uppercase and lowercase letters. Return true if a and b are al... Read More

    #Easy#String#Counting#C++
  • [LeetCode April Challange] Day 06 - Minimum Operations to Make Array Equal

    Apr 06, 2021 About 1 min

    You have an array arr of length n where arr[i] = (2 * i) + 1 for all valid values of i (i.e. 0 <= i < n). In one operation, you can select two indices x and y where 0 <= x, y < n and subtract 1 from arr[x] and add 1 to arr[y] (i.e. perform arr[x] -=1 and arr[y] += 1). The goal is to make all the elements of the array equal. It is gu... Read More

    #Medium#Math#Brillio#C++
  • [LeetCode April Challange] Day 05 - Global and Local Inversions

    Apr 05, 2021 About 2 mins

    We have some permutation A of [0, 1, ..., N - 1], where N is the length of A. The number of (global) inversions is the number of i < j with 0 <= i < j < N and A[i] > A[j]. The number of local inversions is the number of i with 0 <= i < N and A[i] > A[i+1]. Return true if and only if the number of global inversions is e... Read More

    #Medium#Array#Math#Bloomberg#C++
  • [LeetCode April Challange] Day 04 - Design Circular Queue

    Apr 04, 2021 About 4 mins

    Design your implementation of the circular queue. The circular queue is a linear data structure in which the operations are performed based on FIFO (First In First Out) principle and the last position is connected back to the first position to make a circle. It is also called “Ring Buffer”. One of the benefits of the circular queue is that we c... Read More

    #Medium#Array#Linked List#Design#Queue#Facebook#Amazon#Microsoft#Rubrik#Oracle#C++
  • [LeetCode April Challange] Day 03 - Longest Valid Parentheses

    Apr 03, 2021 About 3 mins

    Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring. Example 1: Input: s = "(()" Output: 2 Explanation: The longest valid parentheses substring is "()". Example 2: Input: s = ")()())" Output: 4 Explanation: The longest valid parentheses substring is "()()". Ex... Read More

    #Hard#String#Dynamic Programming#Stack#Amazon#Facebook#Apple#ByteDance#C++
  • [LeetCode April Challange] Day 02 - Ones and Zeroes

    Apr 02, 2021 About 2 mins

    You are given an array of binary strings strs and two integers m and n. Return the size of the largest subset of strs such that there are at most m 0's and n 1's in the subset. A set x is a subset of a set y if all elements of x are also elements of y. Example 1: Input: strs = ["10","0001","111001","1","0"], m = 5, n = 3 Output: 4 Explanatio... Read More

    #Medium#Array#String#Dynamic Programming#Google#C++
  • [LeetCode April Challange] Day 01 - Palindrome Linked List

    Apr 01, 2021 About 1 min

    Given the head of a singly linked list, return true if it is a palindrome. Example 1: Input: head = [1,2,2,1] Output: true Example 2: Input: head = [1,2] Output: false Constraints: The number of nodes in the list is in the range [1, 10^5]. 0 <= Node.val <= 9 Follow up: Could you do it in O(n) time and O(1) space?... Read More

    #Easy#Linked List#Two Pointers#Stack#Recursion#Microsoft#Facebook#Amazon#Adobe#Capital One#Google#Oracle#Bloomberg#Uber#Snapchat#payTM#C++
  • [LeetCode March Challange] Day 10 - Integer to Roman

    Mar 10, 2021 About 2 mins

    Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 V 5 X 10 L 50 C 100 D 500 M 1000 For example, 2 is written as II in Roman numeral, just two one’s added together. 12 is written as XII, which is simply X ... Read More

    #Medium#Hash Table#Math#String#Amazon#Microsoft#Bloomberg#Adobe#Google#Apple#Oracle#C++
  • [LeetCode March Challange] Day 09 - Add One Row to Tree

    Mar 09, 2021 About 3 mins

    Given the root of a binary tree and two integers val and depth, add a row of nodes with value val at the given depth depth. Note that the root node is at depth 1. The adding rule is: Given the integer depth, for each not null tree node cur at the depth depth - 1, create two tree nodes with value val as cur’s left subtree root and right sub... Read More

    #Medium#Tree#Depth-First Search#Breadth-First Search#Binary Tree#Glit Groupe#C++
  • [LeetCode March Challange] Day 08 - Remove Palindromic Subsequences

    Mar 08, 2021 About 1 min

    Given a string s consisting only of letters 'a' and 'b'. In a single step you can remove one palindromic subsequence from s. Return the minimum number of steps to make the given string empty. A string is a subsequence of a given string, if it is generated by deleting some characters of a given string without changing its order. A string is ca... Read More

    #Easy#Two Pointers#String#Amazon#C++
  • [LeetCode March Challange] Day 07 - Design HashMap

    Mar 07, 2021 About 3 mins

    Design a HashMap without using any built-in hash table libraries. Implement the MyHashMap class: MyHashMap() initializes the object with an empty map. void put(int key, int value) inserts a (key, value) pair into the HashMap. If the key already exists in the map, update the corresponding value. int get(int key) returns the value to whic... Read More

    #Easy#Array#Hash Table#Linked List#Design#Hash Function#Goldman Sachs#Apple#Amazon#Oracle#Twitter#LinkedIn#Google#eBay#Microsoft#ServiceNow#VMware#ByteDance#C++
  • [LeetCode March Challange] Day 06 - Short Encoding of Words

    Mar 06, 2021 About 2 mins

    A valid encoding of an array of words is any reference string s and array of indices indices such that: words.length == indices.length The reference string s ends with the '#' character. For each index indices[i], the substring of s starting from indices[i] and up to (but not including) the next '#' character is equal to words[i]... Read More

    #Medium#Array#Hash Table#String#Trie#C++
  • [LeetCode March Challange] Day 05 - Average of Levels in Binary Tree

    Mar 05, 2021 About 1 min

    Given the root of a binary tree, return the average value of the nodes on each level in the form of an array. Answers within 10^-5 of the actual answer will be accepted. Example 1: Input: root = [3,9,20,null,15,7] Output: [3.00000,14.50000,11.00000] Explanation: The average value of nodes on level 0 is 3, on level 1 is 14.5, and on level 2 i... Read More

    #Easy#Tree#Depth-First Search#Breadth-First Search#Binary Tree#Facebook#C++
  • [LeetCode March Challange] Day 04 - Intersection of Two Linked Lists

    Mar 04, 2021 About 3 mins

    Given the heads of two singly linked-lists headA and headB, return the node at which the two lists intersect. If the two linked lists have no intersection at all, return null. For example, the following two linked lists begin to intersect at node c1: It is guaranteed that there are no cycles anywhere in the entire linked structure. Note tha... Read More

    #Easy#Hash Table#Link List#Two Pointers#Microsoft#Amazon#Facebook#ByteDance#LinkedIn#Paypal#Apple#Bloomberg#Intuit#C++
  • [LeetCode March Challange] Day 03 - Missing Number

    Mar 03, 2021 About 2 mins

    Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array. Follow up: Could you implement a solution using only O(1) extra space complexity and O(n) runtime complexity? Example 1: Input: nums = [3,0,1] Output: 2 Explanation: n = 3 since there are 3 numbers, so all... Read More

    #Easy#Array#Hash Table#Math#Bit Manipulation#Sorting#Capital One#Facebook#Amazon#Apple#Oracle#Microsoft#Goldman Sachs#Cisco#Arista Networks#C++
  • [LeetCode March Challange] Day 02 - Set Mismatch

    Mar 02, 2021 About 2 mins

    You have a set of integers s, which originally contains all the numbers from 1 to n. Unfortunately, due to some error, one of the numbers in s got duplicated to another number in the set, which results in repetition of one number and loss of another number. You are given an integer array nums representing the data status of this set after the e... Read More

    #Easy#Array#Hash Table#Bit Manipulation#Sorting#Apple#Amazon#C++
  • [LeetCode March Challange] Day 01 - Distribute Candies

    Mar 01, 2021 About 2 mins

    Alice has n candies, where the ith candy is of type candyType[i]. Alice noticed that she started to gain weight, so she visited a doctor. The doctor advised Alice to only eat n / 2 of the candies she has (n is always even). Alice likes her candies very much, and she wants to eat the maximum number of different types of candies while still follo... Read More

    #Easy#Array#Hash Table#Microsoft#LiveRamp#C++
  • [LeetCode February Challange] Day 28 - Maximum Frequency Stack

    Feb 28, 2021 About 2 mins

    Design a stack-like data structure to push elements to the stack and pop the most frequent element from the stack. Implement the FreqStack class: FreqStack() constructs an empty frequency stack. void push(int val) pushes an integer val onto the top of the stack. int pop() removes and returns the most frequent element in the stack. ... Read More

    #Hard#Hash Table#Stack#Design#Ordered Set#Amazon#Microsoft#Bloomberg#C++
  • [LeetCode February Challange] Day 27 - Divide Two Integers

    Feb 27, 2021 About 2 mins

    Given two integers dividend and divisor, divide two integers without using multiplication, division, and mod operator. Return the quotient after dividing dividend by divisor. The integer division should truncate toward zero, which means losing its fractional part. For example, truncate(8.345) = 8 and truncate(-2.7335) = -2. Note: Assume w... Read More

    #Medium#Math#Bit Manipulation#Facebook#Amazon#Adobe#C++
  • [LeetCode February Challange] Day 26 - Validate Stack Sequences

    Feb 26, 2021 About 1 min

    Given two sequences pushed and popped with distinct values, return true if and only if this could have been the result of a sequence of push and pop operations on an initially empty stack. Example 1: Input: pushed = [1,2,3,4,5], popped = [4,5,3,2,1] Output: true Explanation: We might do the following sequence: push(1), push(2), push(3), push(4... Read More

    #Medium#Array#Stack#Simulation#Google#C++
  • [LeetCode February Challange] Day 25 - Shortest Unsorted Continuous Subarray

    Feb 25, 2021 About 2 mins

    Given an integer array nums, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole array will be sorted in ascending order. Return the shortest such subarray and output its length. Example 1: Input: nums = [2,6,4,8,10,9,15] Output: 5 Explanation: You need to sort [6, 4, 8, 10, 9] in as... Read More

    #Medium#Array#Two Pointers#Stack#Greedy#Sorting#Monotonic Stack#Amazon#Microsoft#C++
  • [LeetCode February Challange] Day 24 - Score of Parentheses

    Feb 24, 2021 About 2 mins

    Given a balanced parentheses string S, compute the score of the string based on the following rule: () has score 1 AB has score A + B, where A and B are balanced parentheses strings. (A) has score 2 * A, where A is a balanced parentheses string. Example 1: Input: "()" Output: 1 Example 2: Input: "(())" Output: 2 Example 3: Input... Read More

    #Medium#String#Stack#Amazon#Google#C++
  • [LeetCode February Challange] Day 23 - Search a 2D Matrix II

    Feb 23, 2021 About 1 min

    Write an efficient algorithm that searches for a target value in an m x n integer matrix. The matrix has the following properties: Integers in each row are sorted in ascending from left to right. Integers in each column are sorted in ascending from top to bottom. Example 1: Input: matrix = [[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[1... Read More

    #Medium#Array#Binary Search#Divide and Conquer#Matrix#Amazon#Microsoft#ByteDance#Bloomberg#Facebook#Nvidia#C++
  • [LeetCode February Challange] Day 22 - Longest Word in Dictionary through Deleting

    Feb 22, 2021 About 1 min

    Given a string s and a string array dictionary, return the longest string in the dictionary that can be formed by deleting some of the given string characters. If there is more than one possible result, return the longest word with the smallest lexicographical order. If there is no possible result, return the empty string. Example 1: Input: s ... Read More

    #Medium#Array#Two Pointers#String#Sorting#Goldman Sachs#C++
  • [LeetCode February Challange] Day 21 - Broken Calculator

    Feb 21, 2021 About 1 min

    On a broken calculator that has a number showing on its display, we can perform two operations: Double: Multiply the number on the display by 2, or; Decrement: Subtract 1 from the number on the display. Initially, the calculator is displaying the number X. Return the minimum number of operations needed to display the number Y. Example ... Read More

    #Medium#Math#Greedy#Nutanix#Bloomberg#C++
  • [LeetCode February Challange] Day 20 - Roman to Integer

    Feb 20, 2021 About 2 mins

    Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 V 5 X 10 L 50 C 100 D 500 M 1000 For example, 2 is written as II in Roman numeral, just two one’s added together. 12 is written as XII, which is simply X ... Read More

    #Easy#Hash Table#Math#String#Boblox#Amazon#Apple#Microsoft#Adobe#Qualtrics#Oracle#Google#Uber#Goldman Sachs#eBay#C++
  • [LeetCode February Challange] Day 19 - Minimum Remove to Make Valid Parentheses

    Feb 19, 2021 About 1 min

    Given a string s of '(' , ')' and lowercase English characters. Your task is to remove the minimum number of parentheses ( '(' or ')', in any positions ) so that the resulting parentheses string is valid and return any valid string. Formally, a parentheses string is valid if and only if: It is the empty string, contains only lowercase char... Read More

    #Medium#String#Stack#Facebook#ByteDance#Bloomberg#Amazon#Goldman Sachs#LinkedIn#C++
  • [LeetCode February Challange] Day 18 - Arithmetic Slices

    Feb 18, 2021 About 1 min

    A sequence of numbers is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same. For example, these are arithmetic sequences: 1, 3, 5, 7, 9 7, 7, 7, 7 3, -1, -5, -9 The following sequence is not arithmetic. 1, 1, 2, 5, 7 A zero-indexed array A consisting of N numb... Read More

    #Medium#Array#Dynamic Programming#Amazon#C++
  • [LeetCode February Challange] Day 17 - Container With Most Water

    Feb 17, 2021 About 1 min

    Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of the line i is at (i, ai) and (i, 0). Find two lines, which, together with the x-axis forms a container, such that the container contains the most water. Notice that you may not slant the ... Read More

    #Medium#Array#Two Pointers#Greedy#Facebook#Amazon#Adobe#Microsoft#Google#Goldman Sachs#Yahoo#Salesforce#tcs#C++
  • [LeetCode February Challange] Day 16 - Letter Case Permutation

    Feb 16, 2021 About 1 min

    Given a string S, we can transform every letter individually to be lowercase or uppercase to create another string. Return a list of all possible strings we could create. You can return the output in any order. Example 1: Input: S = "a1b2" Output: ["a1b2","a1B2","A1b2","A1B2"] Example 2: Input: S = "3z4" Output: ["3z4","3Z4"] Example 3: ... Read More

    #Medium#String#Backtracking#Bit Manipulation#Microsoft#Bloomberg#Amazon#Spotify#C++
  • [LeetCode February Challange] Day 15 - The K Weakest Rows in a Matrix

    Feb 15, 2021 About 2 mins

    You are given an m x n binary matrix mat of 1’s (representing soldiers) and 0’s (representing civilians). The soldiers are positioned in front of the civilians. That is, all the 1’s will appear to the left of all the 0’s in each row. A row i is weaker than a row j if one of the following is true: The number of soldiers in row i is less than... Read More

    #Easy#Array#Binary Search#Sorting#Heap (Priority Queue)#Matrix#Amazon#C++
  • [LeetCode February Challange] Day 14 - Is Graph Bipartite?

    Feb 14, 2021 About 2 mins

    There is an undirected graph with n nodes, where each node is numbered between 0 and n - 1. You are given a 2D array graph, where graph[u] is an array of nodes that node u is adjacent to. More formally, for each v in graph[u], there is an undirected edge between node u and node v. The graph has the following properties: There are no self-edg... Read More

    #Medium#Depth-First Search#Breadth-First Search#Union Find#Graph#Facebook#eBay#ByteDance#C++
  • [LeetCode February Challange] Day 13 - Shortest Path in Binary Matrix

    Feb 13, 2021 About 2 mins

    In an N by N square grid, each cell is either empty (0) or blocked (1). A clear path from top-left to bottom-right has length k if and only if it is composed of cells C_1, C_2, ..., C_k such that: Adjacent cells C_i and C_{i+1} are connected 8-directionally (ie., they are different and share an edge or corner) C_1 is at location (0, 0) (i... Read More

    #Medium#Array#Breadth-First Search#Matrix#Amazon#Google#Facebook#Oracle#Snapchat#Paypal#C++
  • [LeetCode February Challange] Day 12 - Number of Steps to Reduce a Number to Zero

    Feb 12, 2021 About 2 mins

    Given a non-negative integer num, return the number of steps to reduce it to zero. If the current number is even, you have to divide it by 2, otherwise, you have to subtract 1 from it. Example 1: Input: num = 14 Output: 6 Explanation: Step 1) 14 is even; divide by 2 and obtain 7. Step 2) 7 is odd; subtract 1 and obtain 6. Step 3) 6 is even; ... Read More

    #Easy#Math#Bit Manipulation#Amazon#Google#Microsoft#C++
  • [LeetCode February Challange] Day 11 - Valid Anagram

    Feb 11, 2021 About 1 min

    Given two strings s and t , write a function to determine if t is an anagram of s. Example 1: Input: s = "anagram", t = "nagaram" Output: true Example 2: Input: s = "rat", t = "car" Output: false Note: You may assume the string contains only lowercase alphabets. Follow up: What if the inputs contain unicode characters? How would you ad... Read More

    #Easy#Hash Table#String#Sorting#Bloomberg#Microsoft#Facebook#Amazon#Goldman Sachs#Apple#Oracle#Paypal#Adobe#Qualcomm#C++
  • [LeetCode February Challange] Day 10 - Copy List with Random Pointer

    Feb 10, 2021 About 2 mins

    A linked list of length n is given such that each node contains an additional random pointer, which could point to any node in the list, or null. Construct a deep copy of the list. The deep copy should consist of exactly n brand new nodes, where each new node has its value set to the value of its corresponding original node. Both the next and r... Read More

    #Medium#Hash Table#Linked List#Amazon#Facebook#Bloomberg#Microsoft#Oracle#eBay#Yahoo#Qualtrics#C++
  • [LeetCode February Challange] Day 9 - Convert BST to Greater Tree

    Feb 09, 2021 About 2 mins

    Given the root of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in BST. As a reminder, a binary search tree is a tree that satisfies these constraints: The left subtree of a node contains only nodes with keys ... Read More

    #Medium#Tree#Depth-First Search#Binary Search Tree#Binary Tree#Amazon#Facebook#C++
  • [LeetCode February Challange] Day 8 - Peeking Iterator

    Feb 08, 2021 About 2 mins

    Design an iterator that supports the peek operation on a list in addition to the hasNext and the next operations. Implement the PeekingIterator class: PeekingIterator(int[] nums) Initializes the object with the given integer array nums. int next() Returns the next element in the array and moves the pointer to the next element. bool hasN... Read More

    #Medium#Array#Design#Iterator#Google#Apple#C++
  • [LeetCode February Challange] Day 7 - Shortest Distance to a Character

    Feb 07, 2021 About 1 min

    Given a string s and a character c that occurs in s, return an array of integers answer where answer.length == s.length and answer[i] is the distance from index i to the closest occurrence of character c in s. The distance between two indices i and j is abs(i - j), where abs is the absolute value function. Example 1: Input: s = "loveleetcode"... Read More

    #Easy#Array#Two Pointers#String#Apple#C++
  • [LeetCode February Challange] Day 6 - Binary Tree Right Side View

    Feb 06, 2021 About 1 min

    Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom. Example: Input: [1,2,3,null,5,null,4] Output: [1, 3, 4] Explanation: 1 <--- / \ 2 3 <--- \ \ 5 4 <--- Solution Time complexity : O(n) Space c... Read More

    #Medium#Tree#Depth-First Search#Breadth-First Search#Binary Tree#Facebook#Amazon#ByteDance#eBay#Microsoft#Bloomberg#Apple#Accolite#C++
  • [LeetCode February Challange] Day 5 - Simplify Path

    Feb 05, 2021 About 2 mins

    Given a string path, which is an absolute path (starting with a slash '/') to a file or directory in a Unix-style file system, convert it to the simplified canonical path. In a Unix-style file system, a period '.' refers to the current directory, a double period '..' refers to the directory up a level, and any multiple consecutive slashes (i.e.... Read More

    #Medium#String#Stack#Facebok#Amazon#Microsoft#C++
  • [LeetCode February Challange] Day 4 - Longest Harmonious Subsequence

    Feb 04, 2021 About 1 min

    We define a harmonious array as an array where the difference between its maximum value and its minimum value is exactly 1. Given an integer array nums, return the length of its longest harmonious subsequence among all its possible subsequences. A subsequence of array is a sequence that can be derived from the array by deleting some or no elem... Read More

    #Easy#Array#Hash Table#Sorting#Apple#LiveRamp#C++
  • [LeetCode February Challange] Day 3 - Linked List Cycle

    Feb 03, 2021 About 2 mins

    Given head, the head of a linked list, determine if the linked list has a cycle in it. There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally, pos is used to denote the index of the node that tail’s next pointer is connected to. Note that pos is not pa... Read More

    #Easy#Hash Table#Linked List#Two Pointers#Microsoft#Amazon#Facebook#Goldman Sachs#Apple#Google#Tesla#C++
  • [LeetCode February Challange] Day 2 - Trim a Binary Search Tree

    Feb 02, 2021 About 2 mins

    Given the root of a binary search tree and the lowest and highest boundaries as low and high, trim the tree so that all its elements lies in [low, high]. Trimming the tree should not change the relative structure of the elements that will remain in the tree (i.e., any node’s descendant should remain a descendant). It can be proven that there is ... Read More

    #Medium#Tree#Depth-First Search#Binary Search Tree#Binary Tree#Samsung#C++
  • [LeetCode February Challange] Day 1 - Number of 1 Bits

    Feb 01, 2021 About 1 min

    Write a function that takes an unsigned integer and returns the number of ‘1’ bits it has (also known as the Hamming weight). Note: Note that in some languages such as Java, there is no unsigned integer type. In this case, the input will be given as a signed integer type. It should not affect your implementation, as the integer’s internal b... Read More

    #Medium#Bit Manipulation#Facebook#Google#Amazon#Bloomberg#Microsoft#Adobe#ByteDance#Uber#Apple#Flipkart#Salesforce#FactSet#C++
  • 750. Number Of Corner Rectangles

    Jan 31, 2021 About 2 mins

    Given a grid where each entry is only 0 or 1, find the number of corner rectangles. A corner rectangle is 4 distinct 1s on the grid that form an axis-aligned rectangle. Note that only the corners need to have the value 1. Also, all four 1s used must be distinct. Example 1: Input: grid = [[1, 0, 0, 1, 0], [0, 0, 1, 0, 1], [0, 0, 0, 1, 0], ... Read More

    #Medium#Dynamic Programming#Facebook#C++
  • [LeetCode January Challange] Day 31 - Next Permutation

    Jan 31, 2021 About 1 min

    Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such an arrangement is not possible, it must rearrange it as the lowest possible order (i.e., sorted in ascending order). The replacement must be in place and use only constant extra memory. Example 1: Input: nums = [1,2,3]... Read More

    #Medium#Array#Two Pointers#Facebook#Google#Amazon#Bloomberg#Microsoft#Adobe#ByteDance#Uber#Apple#Flipkart#Salesforce#FactSet#C++
  • [LeetCode January Challange] Day 30 - Minimize Deviation in Array

    Jan 30, 2021 About 2 mins

    You are given an array nums of n positive integers. You can perform two types of operations on any element of the array any number of times: If the element is even, divide it by 2. For example, if the array is [1,2,3,4], then you can do this operation on the last element, and the array will be [1,2,3,2]. If the element ... Read More

    #LeetCode#Hard#Array#Greedy#Heap (Priority Queue)#Ordered Set#Samsung#C++
  • [LeetCode January Challange] Day 29 - Vertical Order Traversal of a Binary Tree

    Jan 29, 2021 About 3 mins

    Given the root of a binary tree, calculate the vertical order traversal of the binary tree. For each node at position (row, col), its left and right children will be at positions (row + 1, col - 1) and (row + 1, col + 1) respectively. The root of the tree is at (0, 0). The vertical order traversal of a binary tree is a list of top-to-bottom or... Read More

    #LeetCode#Hard#Hash Table#Tree#Depth-First Search#Breadth-First Search#Binary Tree#Facebook#Bloomberg#Amazon#Apple#ByteDance#Microsoft#C++
  • [LeetCode January Challange] Day 28 - Smallest String With A Given Numeric Value

    Jan 28, 2021 About 1 min

    The numeric value of a lowercase character is defined as its position (1-indexed) in the alphabet, so the numeric value of a is 1, the numeric value of b is 2, the numeric value of c is 3, and so on. The numeric value of a string consisting of lowercase characters is defined as the sum of its characters’ numeric values. For example, the numeric... Read More

    #Medium#String#Greedy#Lendingkart#C++
  • 161. One Edit Distance

    Jan 28, 2021 About 1 min

    Given two strings s and t, return true if they are both one edit distance apart, otherwise return false. A string s is said to be one distance apart from a string t if you can: Insert exactly one character into s to get t. Delete exactly one character from s to get t. Replace exactly one character of s with a different character to get ... Read More

    #Medium#String#Facebook#Amazon#Yandex#C++
  • [LeetCode January Challange] Day 27 - Concatenation of Consecutive Binary Numbers

    Jan 27, 2021 About 1 min

    Given an integer n, return *the **decimal value** of the binary string formed by concatenating the binary representations of 1 to n in order, **modulo** 10^9 + 7*. Example 1: Input: n = 1 Output: 1 Explanation: "1" in binary corresponds to the decimal value 1. Example 2: Input: n = 3 Output: 27 Explanation: In binary, 1, 2, and 3 correspon... Read More

    #Medium#Math#Bit Manipulation#Simulation#Amazon#C++
  • [LeetCode January Challange] Day 25 - Check If All 1's Are at Least Length K Places Away

    Jan 25, 2021 About 1 min

    Given an array nums of 0s and 1s and an integer k, return True if all 1’s are at least k places away from each other, otherwise return False. Example 1: Input: nums = [1,0,0,0,1,0,0,1], k = 2 Output: true Explanation: Each of the 1s are at least 2 places away from each other. Example 2: Input: nums = [1,0,0,1,0,1], k = 2 Output: false E... Read More

    #Easy#Array#United Health Group#C++
  • [LeetCode January Challange] Day 24 - Merge k Sorted Lists

    Jan 24, 2021 About 3 mins

    You are given an array of k linked-lists lists, each linked-list is sorted in ascending order. Merge all the linked-lists into one sorted linked-list and return it. Example 1: Input: lists = [[1,4,5],[1,3,4],[2,6]] Output: [1,1,2,3,4,4,5,6] Explanation: The linked-lists are: [ 1->4->5, 1->3->4, 2->6 ] merging them into on... Read More

    #Hard#Linked List#Divide and Conquer#Heap (Priority Queue)#Merge Sort#Amazon#Facebook#Bloomberg#Databricks#Microsoft#Oracle#Apple#ByteDance#Google#Uber#Adobe#Twitter#Wish#Palantir Technologies#Tesla#C++
  • [LeetCode January Challange] Day 23 - Sort the Matrix Diagonally

    Jan 23, 2021 About 2 mins

    A matrix diagonal is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix’s end. For example, the matrix diagonal starting from mat[2][0], where mat is a 6 x 3 matrix, includes cells mat[2][0], mat[3][1], and mat[4][2]. Given an m x n matr... Read More

    #Medium#Array#Sorting#Matrix#Facebook#Databricks#Google#Robinhood#ServiceNow#C++
  • [LeetCode January Challange] Day 22 - Determine if Two Strings Are Close

    Jan 22, 2021 About 3 mins

    Two strings are considered close if you can attain one from the other using the following operations: Operation 1: Swap any two existing characters. For example, abcde -> aecdb Operation 2: Transform every occurrence of one existing character into another existing character, and do the same with the other character. ... Read More

    #Medium#Hash Table#String#Sorting#Postmates#C++
  • Nested List Weight Sum

    Jan 21, 2021 About 4 mins

    You are given a nested list of integers nestedList. Each element is either an integer or a list whose elements may also be integers or other lists. The depth of an integer is the number of lists that it is inside of. For example, the nested list [1,[2,2],[[3],2],1] has each integer’s value set to its depth. Return the sum of each integer in ne... Read More

    #LeetCode#Easy#Depth-First Search#Breadth-First Search#Facebook#Amazon#LinkedIn#C++
  • [LeetCode January Challange] Day 21 - Find the Most Competitive Subsequence

    Jan 21, 2021 About 1 min

    Given an integer array nums and a positive integer k, return the most competitive subsequence of nums of size k. An array’s subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the array. We define that a subsequence a is more competitive than a subsequence b (of the same length) if in the first position w... Read More

    #Medium#Array#Stack#Greedy#Monotonic Stack#C++
  • [LeetCode January Challange] Day 20 - Valid Parentheses

    Jan 20, 2021 About 1 min

    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. Example 1: Input: s = "()" Output: true Example 2: Input: s = "()[]{}" Out... Read More

    #Medium#String#Stack#Amazon#Microsoft#Goldman Sachs#Google#Facebook#Bloomberg#Adobe#Apple#eBay#Oracle#Yandex#tcs#C++
  • [LeetCode January Challange] Day 19 - Longest Palindromic Substring

    Jan 19, 2021 About 1 min

    Given a string s, return the longest palindromic substring in s. Example 1: Input: s = "babad" Output: "bab" Note: "aba" is also a valid answer. Example 2: Input: s = "cbbd" Output: "bb" Example 3: Input: s = "a" Output: "a" Example 4: Input: s = "ac" Output: "a" Constraints: 1 <= s.length <= 1000 s consist of on... Read More

    #Medium#String#Dynamic Programming#Amazon#Microsoft#Goldman Sachs#Google#Facebook#Bloomberg#Adobe#Apple#eBay#Oracle#Yandex#tcs#C++
  • [LeetCode January Challange] Day 18 - Max Number of K-Sum Pairs

    Jan 18, 2021 About 2 mins

    You are given an integer array nums and an integer k. In one operation, you can pick two numbers from the array whose sum equals k and remove them from the array. Return the maximum number of operations you can perform on the array. Example 1: Input: nums = [1,2,3,4], k = 5 Output: 2 Explanation: Starting with nums = [1,2,3,4]: - Remove numb... Read More

    #Medium#Array#Hash Table#Two Pointers#Sorting#DE Shaw#C++
  • [LeetCode January Challange] Day 17 - Count Sorted Vowel Strings

    Jan 17, 2021 About 3 mins

    Given an integer n, return the number of strings of length n that consist only of vowels (a, e, i, o, u) and are lexicographically sorted. A string s is lexicographically sorted if for all valid i, s[i] is the same as or comes before s[i+1] in the alphabet. Example 1: Input: n = 1 Output: 5 Explanation: The 5 sorted strings that consist of vo... Read More

    #Medium#Dynamic Programming#Nira Finance#C++
  • [LeetCode January Challange] Day 16 - Kth Largest Element in an Array

    Jan 16, 2021 About 1 min

    Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. Example 1: Input: [3,2,1,5,6,4] and k = 2 Output: 5 Example 2: Input: [3,2,3,1,2,4,5,5,6] and k = 4 Output: 4 Note: You may assume k is always valid, 1 ≤ k ≤ array’s length. Solution Min-Heap T... Read More

    #Medium#Array#Divide and Conquer#Sorting#Heap (Priority Queue)#Quickselect#Facebook#Amazon#ByteDance#Walmart Labs#Apple#Microsoft#Salesforce#Google#LinkedIn#Adobe#Oracle#Expedia#Spotify#Zillow#C++
  • [LeetCode January Challange] Day 15 - Get Maximum in Generated Array

    Jan 15, 2021 About 2 mins

    You are given an integer n. An array nums of length n + 1 is generated in the following way: nums[0] = 0 nums[1] = 1 nums[2 * i] = nums[i] when 2 <= 2 * i <= n nums[2 * i + 1] = nums[i] + nums[i + 1] when 2 <= 2 * i + 1 <= n Return the maximum integer in the array nums​​​. Example 1: I... Read More

    #Easy#Array#Dynamic Programming#Simulation#C++
  • [LeetCode January Challange] Day 14 - Minimum Operations to Reduce X to Zero

    Jan 14, 2021 About 2 mins

    You are given an integer array nums and an integer x. In one operation, you can either remove the leftmost or the rightmost element from the array nums and subtract its value from x. Note that this modifies the array for future operations. Return the minimum number of operations to reduce x to exactly 0 if it’s possible, otherwise, return -1. ... Read More

    #Medium#Array#Hash Table#Binary Search#Sliding Window#Prefix Sum#Google#C++
  • [LeetCode January Challange] Day 13 - Boats to Save People

    Jan 13, 2021 About 1 min

    The i-th person has weight people[i], and each boat can carry a maximum weight of limit. Each boat carries at most 2 people at the same time, provided the sum of the weight of those people is at most limit. Return the minimum number of boats to carry every given person. (It is guaranteed each person can be carried by a boat.) Example 1: Inp... Read More

    #Medium#Array#Two Pointers#Greedy#Sorting#Roblox#C++
  • [LeetCode January Challange] Day 12 - Add Two Numbers

    Jan 12, 2021 About 1 min

    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. Example 1: Input: l1 = ... Read More

    #Medium#Linked List#Math#Recursion#Amazon#Bloomberg#Microsoft#Adobe#Apple#Google#Facebook#Uber#Yahoo#Coupang#VMware#Walmart Labs#Paypal#Docusign#C++
  • [LeetCode January Challange] Day 11 - Merge Sorted Array

    Jan 11, 2021 About 1 min

    Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. The number of elements initialized in nums1 and nums2 are m and n respectively. You may assume that nums1 has enough space (size that is equal to m + n) to hold additional elements from nums2. Example 1: Input: nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2... Read More

    #Easy#Array#Two Pointers#Sorting#Facebook#Microsoft#Amazon#Apple#IBM#Bloomberg#Oracle#Goldman Sachs#C++
  • Find Root of N-Ary Tree

    Jan 11, 2021 About 2 mins

    You are given all the nodes of an N-ary tree as an array of Node objects, where each node has a unique value. Return the root of the N-ary tree. Custom testing: An N-ary tree can be serialized as represented in its level order traversal where each group of children is separated by the null value (see examples). For example, the above tree ... Read More

    #Medium#Google#C++
  • [LeetCode January Challange] Day 9 - Word Ladder

    Jan 09, 2021 About 2 mins

    Given two words beginWord and endWord, and a dictionary wordList, return the length of the shortest transformation sequence from beginWord to endWord, such that: Only one letter can be changed at a time. Each transformed word must exist in the word list. Return 0 if there is no such transformation sequence. Example 1: Input: beginWord =... Read More

    #Hard#Hash Table#String#Breadth-First Search#Amazon Lyft#Faceboook#Google#Qualtrics#Microsoft#Bloomberg#Zillow#Oracle#Uber#Yahoo#Apple#Citadel#C++
  • [LeetCode January Challange] Day 8 - Check If Two String Arrays are Equivalent

    Jan 08, 2021 About 1 min

    Given two string arrays word1 and word2, return true if the two arrays represent the same string, and false otherwise. A string is represented by an array if the array elements concatenated in order forms the string. Example 1: Input: word1 = ["ab", "c"], word2 = ["a", "bc"] Output: true Explanation: word1 represents string "ab" + "c" -> "... Read More

    #Easy#Array#String#Facebook#C++
  • Palindrome Permutation

    Jan 07, 2021 About 1 min

    Given a string, determine if a permutation of the string could form a palindrome. Example 1: Input: "code" Output: false Example 2: Input: "aab" Output: true Example 3: Input: "carerac" Output: true Solution Time complexity : O(n) Space complexity : O(1) class Solution { public: bool canPermutePalindrome(string s) { bit... Read More

    #Easy#Hash Table#Facebook#Microsoft#C++
  • [LeetCode January Challange] Day 7 - Longest Substring Without Repeating Characters

    Jan 07, 2021 About 2 mins

    Given a string s, find the length of the longest substring without repeating characters. Example 1: Input: s = "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length of 3. Example 2: Input: s = "bbbbb" Output: 1 Explanation: The answer is "b", with the length of 1. Example 3: Input: s = "pwwkew" Output: 3 Explanation: The... Read More

    #Medium#Hash Table#String#Sliding Window#Amazon#Bloomberg#Microsoft#Facebook#Apple#Google#Adobe#Goldman Sachs#ByteDance#Oracle#Alation#Yahoo#Uber#VMWare#Morgan Stanley#eBay#Expedia#SAP#Splunk#Spotify#C++
  • [LeetCode January Challange] Day 6 - Kth Missing Positive Number

    Jan 06, 2021 About 2 mins

    Given an array arr of positive integers sorted in a strictly increasing order, and an integer k. Find the k-th positive integer that is missing from this array. Example 1: Input: arr = [2,3,4,7,11], k = 5 Output: 9 Explanation: The missing positive integers are [1,5,6,8,9,10,12,13,...]. The 5th missing positive integer is 9. Example 2: Inp... Read More

    #Easy#Array#Binary Search#Facebook#Microsoft#C++
  • [LeetCode January Challange] Day 5 - Remove Duplicates from Sorted List II

    Jan 05, 2021 About 1 min

    Given the head of a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Return the linked list sorted as well. Example 1: Input: head = [1,2,3,3,4,4,5] Output: [1,2,5] Example 2: Input: head = [1,1,1,2,3] Output: [2,3] Constraints: The number of nodes in the list is... Read More

    #Medium#Linked List#Two Pointers#Amazon#C++
  • [LeetCode January Challange] Day 4 - Merge Two Sorted Lists

    Jan 04, 2021 About 1 min

    Merge two sorted linked lists and return it as a sorted list. The list should be made by splicing together the nodes of the first two lists. Example 1: Input: l1 = [1,2,4], l2 = [1,3,4] Output: [1,1,2,3,4,4] Example 2: Input: l1 = [], l2 = [] Output: [] Example 3: Input: l1 = [], l2 = [0] Output: [0] Constraints: The number of no... Read More

    #Easy#Linked List#Recursion#Amazon#Adobe#Capital One#Google#Facebook#Bloomberg#Oracle#Apple#Microsoft#IBM#Uber#C++
  • [LeetCode January Challange] Day 3 - Beautiful Arrangement

    Jan 03, 2021 About 1 min

    Suppose you have n integers labeled 1 through n. A permutation of those n integers perm (1-indexed) is considered a beautiful arrangement if for every i (1 <= i <= n), either of the following is true: perm[i] is divisible by i. i is divisible by perm[i]. Given an integer n, return the number of the beautiful arrangements that you c... Read More

    #Medium#Array#Dynamic Programming#Backtracking#Bit Manipulation#Bit Mask#Mathworks#Cisco#C++
  • [LeetCode January Challange] Day 2 - Find a Corresponding Node of a Binary Tree in a Clone of That Tree

    Jan 02, 2021 About 2 mins

    Given two binary trees original and cloned and given a reference to a node target in the original tree. The cloned tree is a copy of the original tree. Return a reference to the same node in the cloned tree. Note that you are not allowed to change any of the two trees or the target node and the answer must be a reference to a node in the clon... Read More

    #Medium#Tree#Depth-First Search#Breadth-First Search#Binary Tree#Facebook#C++
  • [LeetCode January Challange] Day 1 - Check Array Formation Through Concatenation

    Jan 01, 2021 About 1 min

    You are given an array of distinct integers arr and an array of integer arrays pieces, where the integers in pieces are distinct. Your goal is to form arr by concatenating the arrays in pieces in any order. However, you are not allowed to reorder the integers in each array pieces[i]. Return true if it is possible to form the array arr from piec... Read More

    #Easy#Array#Hash Table#CodeSignal#C++
  • [LeetCode December Challange] Day 13 - Burst Balloons

    Dec 13, 2020 About 1 min

    Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by array nums. You are asked to burst all the balloons. If the you burst balloon i you will get nums[left] * nums[i] * nums[right] coins. Here left and right are adjacent indices of i. After the burst, the left and right then becomes adjacent. Find ... Read More

    #Hard#Array#Dynamic Programming#C++
  • [LeetCode December Challange] Day 12 - Smallest Subtree with all the Deepest Nodes

    Dec 12, 2020 About 2 mins

    Given the root of a binary tree, the depth of each node is the shortest distance to the root. Return the smallest subtree such that it contains all the deepest nodes in the original tree. A node is called the deepest if it has the largest depth possible among any node in the entire tree. The subtree of a node is tree consisting of that node, ... Read More

    #Medium#Hash Table#Tree#Depth-first Search#Breadth-first Search#Binary Tree#Facebook#C++
  • [LeetCode December Challange] Day 11 - Remove Duplicates from Sorted Array II

    Dec 11, 2020 About 2 mins

    Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twice and return the new length. Do not allocate extra space for another array; you must do this by modifying the input array in-place with O(1) extra memory. Clarification: Confused why the returned value is an integer, but your answer is an array... Read More

    #Medium#Array#Two pointers#VMware#C++
  • [LeetCode December Challange] Day 10 - Valid Mountain Array

    Dec 10, 2020 About 1 min

    Given an array of integers arr, return true if and only if it is a valid mountain array. Recall that arr is a mountain array if and only if: arr.length >= 3 There exists some i with 0 < i < arr.length - 1 such that: arr[0] < arr[1] < ... < arr[i - 1] < A[i] arr[i] > ... Read More

    #Easy#Array#Google#C++
  • [LeetCode December Challange] Day 9 - Binary Search Tree Iterator

    Dec 09, 2020 About 3 mins

    Implement the BSTIterator class that represents an iterator over the in-order traversal of a binary search tree (BST): BSTIterator(TreeNode root) Initializes an object of the BSTIterator class. The root of the BST is given as part of the constructor. The pointer should be initialized to a non-existent number smaller than any element... Read More

    #Medium#Stack#Tree#Design#Binary Search Tree#Binary Tree#Iterator#Facebook#Amazon#Bloomberg#Microsoft#Google#ByteDance#C++
  • [LeetCode December Challange] Day 8 - Pairs of Songs With Total Durations Divisible by 60

    Dec 08, 2020 About 1 min

    You are given a list of songs where the i-th song has a duration of time[i] seconds. Return the number of pairs of songs for which their total duration in seconds is divisible by 60. Formally, we want the number of indices i, j such that i < j with (time[i] + time[j]) % 60 == 0. Example 1: Input: time = [30,20,150,100,40] Output: 3 Explana... Read More

    #Medium#Array#Hash Table#Counting#Amazon#Citrix#IBM#Paypal#C++
  • [LeetCode December Challange] Day 7 - Spiral Matrix II

    Dec 07, 2020 About 1 min

    Given a positive integer n, generate an n x n matrix filled with elements from 1 to n^2 in spiral order. Example 1: Input: n = 3 Output: [[1,2,3],[8,9,4],[7,6,5]] Example 2: Input: n = 1 Output: [[1]] Constraints: 1 <= n <= 20 Solution Time complexity : O(n^2) Space complexity : O(1) class Solution { public: v... Read More

    #Medium#Array#Simulation#Microsoft#C++
  • Shortest Word Distance

    Dec 06, 2020 About 1 min

    Given a list of words and two words word1 and word2, return the shortest distance between these two words in the list. Example: Assume that words = ["practice", "makes", "perfect", "coding", "makes"]. Input: word1 = "coding", word2 = "practice" Output: 3 Input: word1 = "makes", word2 = "coding" Output: 1 Note: You may assume that word1... Read More

    #Easy#Array#Goldman Sachs#C++
  • [LeetCode December Challange] Day 6 - Populating Next Right Pointers in Each Node II

    Dec 06, 2020 About 2 mins

    Given a binary tree struct Node { int val; Node *left; Node *right; Node *next; } Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL. Initially, all next pointers are set to NULL. Follow up: You may only use constant extra space. Recursive ... Read More

    #Medium#Tree#Depth-First Search#Breath-First Search#Binary Tree#Bloomberg#Amazon#Facebook#Google#C++
  • [LeetCode December Challange] Day 5 - Can Place Flowers

    Dec 05, 2020 About 1 min

    You have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted in adjacent plots. Given an integer array flowerbed containing 0’s and 1’s, where 0 means empty and 1 means not empty, and an integer n, return if n new flowers can be planted in the flowerbed without violating the no-adjacent-... Read More

    #Easy#Array#Greedy#Facebook#LinkedIn#C++
  • [LeetCode December Challange] Day 4 - The kth Factor of n

    Dec 04, 2020 About 1 min

    Given two positive integers n and k. A factor of an integer n is defined as an integer i where n % i == 0. Consider a list of all factors of n sorted in ascending order, return the kth factor in this list or return -1 if n has less than k factors. Example 1: Input: n = 12, k = 3 Output: 3 Explanation: Factors list is [1, 2, 3, 4, 6, 12], the... Read More

    #Medium#Math#Expedia#C++
  • [LeetCode December Challange] Day 3 - Increasing Order Search Tree

    Dec 03, 2020 About 1 min

    Given the root of a binary search tree, rearrange the tree in in-order so that the leftmost node in the tree is now the root of the tree, and every node has no left child and only one right child. Example 1: Input: root = [5,3,6,2,4,null,8,1,null,null,null,7,9] Output: [1,null,2,null,3,null,4,null,5,null,6,null,7,null,8,null,9] Example 2: ... Read More

    #Easy#Stack#Tree#Depth-First Search#Binary Search Tree#Apple#Amazon#C++
  • [LeetCode December Challange] Day 2 - Linked List Random Node

    Dec 02, 2020 About 2 mins

    Given a singly linked list, return a random node’s value from the linked list. Each node must have the same probability of being chosen. Follow up: What if the linked list is extremely large and its length is unknown to you? Could you solve this efficiently without using extra space? Example: // Init a singly linked list [1,2,3]. ListNode he... Read More

    #Medium#Linked List#Math#Reservoir Sampling#Randomized#Amazon#C++
  • Cooperative project - PHM program

    Dec 01, 2020 About 1 min

    Read More

    #Python#AI#PHM
  • [LeetCode December Challange] Day 1 - Maximum Depth of Binary Tree

    Dec 01, 2020 About 1 min

    Given the root of a binary tree, return its maximum depth. A binary tree’s maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. Example 1: Input: root = [3,9,20,null,null,15,7] Output: 3 Example 2: Input: root = [1,null,2] Output: 2 Example 3: Input: root = [] Output: 0 Example ... Read More

    #Easy#Tree#Depth-first Search#Breadth-First Search#Binary Tree#Amazon#Facebook#Adobe#Microsoft#C++
  • [LeetCode November Challange] Day 3 - Consecutive Characters

    Nov 03, 2020 About 1 min

    Given a string s, the power of the string is the maximum length of a non-empty substring that contains only one unique character. Return the power of the string. Example 1: Input: s = "leetcode" Output: 2 Explanation: The substring "ee" is of length 2 with the character 'e' only. Example 2: Input: s = "abbcccddddeeeeedcba" Output: 5 Explanat... Read More

    #Easy#String#Microsoft#C++
  • [LeetCode November Challange] Day 2 - Insertion Sort List

    Nov 02, 2020 About 1 min

    Sort a linked list using insertion sort. A graphical example of insertion sort. The partial sorted list (black) initially contains only the first element in the list. With each iteration one element (red) is removed from the input data and inserted in-place into the sorted list Algorithm of Insertion Sort: Insertion sort iterates, consumin... Read More

    #Medium#Linked List#Sorting#Microsoft#Bloomberg#C++
  • [LeetCode November Challange] Day 1 - Convert Binary Number in a Linked List to Integer

    Nov 01, 2020 About 1 min

    Given head which is a reference node to a singly-linked list. The value of each node in the linked list is either 0 or 1. The linked list holds the binary representation of a number. Return the decimal value of the number in the linked list. Example 1: Input: head = [1,0,1] Output: 5 Explanation: (101) in base 2 = (5) in base 10 Example 2:... Read More

    #Easy#Linked List#Math#Mathworks#Cisco#Citrix#C++
  • [LeetCode October Challange] Day 31 - Recover Binary Search Tree

    Oct 31, 2020 About 1 min

    You are given the root of a binary search tree (BST), where exactly two nodes of the tree were swapped by mistake. Recover the tree without changing its structure. Follow up: A solution using O(n) space is pretty straight forward. Could you devise a constant space solution? Example 1: Input: root = [1,3,null,null,2] Output: [3,1,null,null,2]... Read More

    #Hard#Tree#Depth-First Search#Binary Search Tree#Binary Tree#Amazon#Oracle#Microsoft#Uber#Google#C++
  • [LeetCode October Challange] Day 30 - Number of Longest Increasing Subsequence

    Oct 30, 2020 About 1 min

    Given an integer array nums, return the number of longest increasing subsequences. Example 1: Input: nums = [1,3,5,4,7] Output: 2 Explanation: The two longest increasing subsequences are [1, 3, 4, 7] and [1, 3, 5, 7]. Example 2: Input: nums = [2,2,2,2,2] Output: 5 Explanation: The length of longest continuous increasing subsequence is 1, and ... Read More

    #Medium#Array#Dynamic Programming#Binary Indexed Tree#Segment Tree#Bloomberg#C++
  • [LeetCode October Challange] Day 29 - Maximize Distance to Closest Person

    Oct 29, 2020 About 2 mins

    You are given an array representing a row of seats where seats[i] = 1 represents a person sitting in the i-th seat, and seats[i] = 0 represents that the i-th seat is empty (0-indexed). There is at least one empty seat, and at least one person sitting. Alex wants to sit in the seat such that the distance between him and the closest person to hi... Read More

    #Medium#Array#Audible#Amazon#Microsoft#C++
  • [LeetCode October Challange] Day 28 - Summary Ranges

    Oct 28, 2020 About 1 min

    You are given a sorted unique integer array nums. Return the smallest sorted list of ranges that cover all the numbers in the array exactly. That is, each element of nums is covered by exactly one of the ranges, and there is no integer x such that x is in one of the ranges but not in nums. Each range [a,b] in the list should be output as: "... Read More

    #Easy#Array#Capital One#C++
  • [LeetCode October Challange] Day 27 - Linked List Cycle II

    Oct 27, 2020 About 2 mins

    Given a linked list, return the node where the cycle begins. If there is no cycle, return null. There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally, pos is used to denote the index of the node that tail’s next pointer is connected to. Note that pos ... Read More

    #Medium#Hash Table#Linked List#Two Pointers#Microsoft#Apple#C++
  • [LeetCode October Challange] Day 26 - Champagne Tower

    Oct 26, 2020 About 2 mins

    We stack glasses in a pyramid, where the first row has 1 glass, the second row has 2 glasses, and so on until the 100-th row. Each glass holds one cup of champagne. Then, some champagne is poured into the first glass at the top. When the topmost glass is full, any excess liquid poured will fall equally to the glass immediately to the left and... Read More

    #Medium#Dynamic Programming#Google#C++
  • [LeetCode October Challange] Day 25 - Stone Game IV

    Oct 25, 2020 About 2 mins

    Alice and Bob take turns playing a game, with Alice starting first. Initially, there are n stones in a pile. On each player’s turn, that player makes a move consisting of removing any non-zero square number of stones in the pile. Also, if a player cannot make a move, he/she loses the game. Given a positive integer n. Return True if and only ... Read More

    #Hard#Math#Dynamic Programming#Game Theory#Microsoft#C++
  • [LeetCode October Challange] Day 24 - Bag of Tokens

    Oct 24, 2020 About 2 mins

    You have an initial power of P, an initial score of 0, and a bag of tokens where tokens[i] is the value of the i-th token (0-indexed). Your goal is to maximize your total score by potentially playing each token in one of two ways: If your current power is at least tokens[i], you may play the i-th token face up, losing tokens[i] power and gai... Read More

    #Medium#Array#Two Pointers#Greedy#Sorting#Google#C++
  • 702. Search in a Sorted Array of Unknown Size

    Oct 23, 2020 About 2 mins

    Given an integer array sorted in ascending order, write a function to search target in nums. If target exists, then return its index, otherwise return -1. However, the array size is unknown to you. You may only access the array using an ArrayReader interface, where ArrayReader.get(k) returns the element of the array at index k (0-indexed). You... Read More

    #Medium#Binary Search#Microsoft#C++
  • [LeetCode October Challange] Day 23 - 132 pattern

    Oct 23, 2020 About 3 mins

    Given an array of n integers nums, a 132 pattern is a subsequence of three integers nums[i], nums[j] and nums[k] such that i < j < k and nums[i] < nums[k] < nums[j]. Return true if there is a 132 pattern in nums, otherwise, return false. Follow up: The O(n^2) is trivial, could you come up with the O(n logn) or the O(n) solution? E... Read More

    #Medium#Array#Binary Search#Stack#Monotonic Stack#Ordered Set#Google#Amazon#Oracle#C++
  • [LeetCode October Challange] Day 22 - Minimum Depth of Binary Tree

    Oct 22, 2020 About 2 mins

    Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. Note: A leaf is a node with no children. Example 1: Input: root = [3,9,20,null,null,15,7] Output: 2 Example 2: Input: root = [2,null,3,null,4,null,5,null,6] Output: 5 Constraints... Read More

    #Easy#Tree#Depth-first Search#Breadth-first Search#Binary Tree#Facebook#Apple#C++
  • [LeetCode October Challange] Day 21 - Asteroid Collision

    Oct 21, 2020 About 2 mins

    We are given an array asteroids of integers representing asteroids in a row. For each asteroid, the absolute value represents its size, and the sign represents its direction (positive meaning right, negative meaning left). Each asteroid moves at the same speed. Find out the state of the asteroids after all collisions. If two asteroids meet, th... Read More

    #Medium#Array#Stack#Amazon#Lyft#ByteDance#Google#C++
  • 253. Meeting Rooms II

    Oct 20, 2020 About 1 min

    Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei), find the minimum number of conference rooms required. Example 1: Input: [[0, 30],[5, 10],[15, 20]] Output: 2 Example 2: Input: [[7,10],[2,4]] Output: 1 NOTE: input types have been changed on April 15, 2019. Please reset to default ... Read More

    #Medium#Heap#Greedy#Sort#Amazon#Bloomberg#Facebook#eBay#Google#Apple#Microsoft#Yandex#Snapchat#Oracle#Roblox#C++
  • [LeetCode October Challange] Day 20 - Clone Graph

    Oct 20, 2020 About 4 mins

    Given a reference of a node in a connected undirected graph. Return a deep copy (clone) of the graph. Each node in the graph contains a val (int) and a list (List[Node]) of its neighbors. class Node { public int val; public List<Node> neighbors; } Test case format: For simplicity sake, each node’s value is the same as the nod... Read More

    #Medium#Hash Table#Depth-First Search#Breadth-First Search#Graph#Facebook#Google#Amazon#Microsoft#Qualtrics#Apple#DiDi#Docusign#C++
  • [LeetCode October Challange] Day 19 - Minimum Domino Rotations For Equal Row

    Oct 19, 2020 About 2 mins

    In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.) We may rotate the i-th domino, so that A[i] and B[i] swap values. Return the minimum number of rotations so that all the values in A are the same, or all the values in B ... Read More

    #Medium#Array#Greedy#Google#C++
  • [LeetCode October Challange] Day 18 - Best Time to Buy and Sell Stock IV

    Oct 18, 2020 About 2 mins

    You are given an integer array prices where prices[i] is the price of a given stock on the i-th day. Design an algorithm to find the maximum profit. You may complete at most k transactions. Notice that you may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again). Example 1: Input: k = 2, pric... Read More

    #Hard#Array#Dynamic Programming#Amazon#Bloomberg#Google#Citadel#C++
  • [LeetCode October Challange] Day 17 - Repeated DNA Sequences

    Oct 17, 2020 About 2 mins

    All DNA is composed of a series of nucleotides abbreviated as 'A', 'C', 'G', and 'T', for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA. Write a function to find all the 10-letter-long sequences (substrings) that occur more than once in a DNA molecule. Example 1: Input: s = "AAAA... Read More

    #Medium#Hash Table#String#Bit Manipulation#Sliding Window#Rolling Hash#Hash Function#Amazon#Apple#Microsoft#C++
  • [LeetCode October Challange] Day 16 - Search a 2D Matrix

    Oct 16, 2020 About 1 min

    Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted from left to right. The first integer of each row is greater than the last integer of the previous row. Example 1: Input: matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,50]], target = 3 Outpu... Read More

    #Medium#Array#Binary Search#Matrix#Amazon#Microsoft#Facebook#Bloomberg#Adobe#C++
  • [LeetCode October Challange] Day 15 - Rotate Array

    Oct 15, 2020 About 1 min

    Given an array, rotate the array to the right by k steps, where k is non-negative. Follow up: Try to come up as many solutions as you can, there are at least 3 different ways to solve this problem. Could you do it in-place with O(1) extra space? Example 1: Input: nums = [1,2,3,4,5,6,7], k = 3 Output: [5,6,7,1,2,3,4] Explanation: rotate 1... Read More

    #Medium#Array#Math#Two Pointers#Facebook#Microsoft#Apple#C++
  • 170. Two Sum III - Data structure design

    Oct 14, 2020 About 2 mins

    Design a data structure that accepts a stream of integers and checks if it has a pair of integers that sum up to a particular value. Implement the TwoSum class : TwoSum() Initializes the TwoSum object, with an empty array initially. void add(int number) Adds number to the data structure. boolean find(int value) Returns true if there exis... Read More

    #Easy#Hash Table#LinkedIn#C++
  • [LeetCode October Challange] Day 14 - House Robber II

    Oct 14, 2020 About 2 mins

    You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are arranged in a circle. That means the first house is the neighbor of the last one. Meanwhile, adjacent houses have a security system connected, and it will automatically contact the police if two adja... Read More

    #Medium#Array#Dynamic Programming#Amazon#eBay#C++
  • [LeetCode October Challange] Day 13 - Sort List

    Oct 13, 2020 About 3 mins

    Given the head of a linked list, return the list after sorting it in ascending order. Follow up: Can you sort the linked list in O(n logn) time and O(1) memory (i.e. constant space)? Example 1: Input: head = [4,2,1,3] Output: [1,2,3,4] Example 2: Input: head = [-1,5,3,4,0] Output: [-1,0,3,4,5] Example 3: Input: head = [] Output: [] ... Read More

    #Medium#Linked List#Two Pointers#Divide and Conquer#Sorting#Merge Sort#Amazon#ByteDance#Yahoo#C++
  • [LeetCode October Challange] Day 12 - Buddy Strings

    Oct 12, 2020 About 2 mins

    Given two strings A and B of lowercase letters, return true if you can swap two letters in A so the result is equal to B, otherwise, return false. Swapping letters is defined as taking two indices i and j (0-indexed) such that i != j and swapping the characters at A[i] and A[j]. For example, swapping at indices 0 and 2 in "abcd" results in "cba... Read More

    #Easy#Hash Table#String#Facebook#C++
  • [LeetCode October Challange] Day 11 - Remove Duplicate Letters

    Oct 11, 2020 About 1 min

    Given a string s, remove duplicate letters so that every letter appears once and only once. You must make sure your result is the smallest in lexicographical order among all possible results. Note: This question is the same as 1081 Example 1: Input: s = "bcabc" Output: "abc" Example 2: Input: s = "cbacdcbc" Output: "acdb" Constraints: ... Read More

    #Medium#String#Stack#Greedy#Monotonic Stack#Amazon#ByteDance#C++
  • [LeetCode October Challange] Day 10 - Minimum Number of Arrows to Burst Balloons

    Oct 10, 2020 About 2 mins

    There are some spherical balloons spread in two-dimensional space. For each balloon, provided input is the start and end coordinates of the horizontal diameter. Since it’s horizontal, y-coordinates don’t matter, and hence the x-coordinates of start and end of the diameter suffice. The start is always smaller than the end. An arrow can be shot u... Read More

    #Medium#Array#Greedy#Sorting#Facebook#Amazon#C++
  • [LeetCode October Challange] Day 9 - Serialize and Deserialize BST

    Oct 09, 2020 About 2 mins

    Serialization is converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another computer environment. Design an algorithm to serialize and deserialize a binary search tree. There is no restriction ... Read More

    #Medium#String#Tree#Depth-First-Search#Breadth-First-Search#Design#Binary Search Tree#Binary Tree#Amazon#Facebook#ByteDance#C++
  • [LeetCode October Challange] Day 8 - Binary Search

    Oct 08, 2020 About 1 min

    Given a sorted (in ascending order) integer array nums of n elements and a target value, write a function to search target in nums. If target exists, then return its index, otherwise return -1. Example 1: Input: nums = [-1,0,3,5,9,12], target = 9 Output: 4 Explanation: 9 exists in nums and its index is 4 Example 2: Input: nums = [-1,0,3,5,9,1... Read More

    #Easy#Array#Binary Search#Amazon#Paypal#C++
  • [LeetCode October Challange] Day 7 - Rotate List

    Oct 07, 2020 About 1 min

    Given a linked list, rotate the list to the right by k places, where k is non-negative. Example 1: Input: 1->2->3->4->5->NULL, k = 2 Output: 4->5->1->2->3->NULL Explanation: rotate 1 steps to the right: 5->1->2->3->4->NULL rotate 2 steps to the right: 4->5->1->2->3->NULL Example 2: I... Read More

    #Medium#Linked List#Two Pointers#Amazon#Bloomberg#Adobe#C++
  • [LeetCode October Challange] Day 6 - Insert into a Binary Search Tree

    Oct 06, 2020 About 2 mins

    You are given the root node of a binary search tree (BST) and a value to insert into the tree. Return the root node of the BST after the insertion. It is guaranteed that the new value does not exist in the original BST. Notice that there may exist multiple valid ways for the insertion, as long as the tree remains a BST after insertion. You can ... Read More

    #Medium#Tree#Binary Search Tree#Binary Tree#Amazon#Microsoft#C++
  • [LeetCode October Challange] Day 5 - Complement of Base 10 Integer

    Oct 05, 2020 About 1 min

    Every non-negative integer N has a binary representation. For example, 5 can be represented as "101" in binary, 11 as "1011" in binary, and so on. Note that except for N = 0, there are no leading zeroes in any binary representation. The complement of a binary representation is the number in binary you get when changing every 1 to a 0 and 0 to... Read More

    #Easy#Bit Manipulation#Cloudera#C++
  • [LeetCode October Challange] Day 4 - Remove Covered Intervals

    Oct 04, 2020 About 1 min

    Given a list of intervals, remove all intervals that are covered by another interval in the list. Interval [a,b) is covered by interval [c,d) if and only if c <= a and b <= d. After doing so, return the number of remaining intervals. Example 1: Input: intervals = [[1,4],[3,6],[2,8]] Output: 2 Explanation: Interval [3,6] is covered by [2... Read More

    #Medium#Array#Sorting#Goldman Sachs#Microsoft#C++
  • [LeetCode October Challange] Day 3 - K-diff Pairs in an Array

    Oct 03, 2020 About 1 min

    Given an array of integers nums and an integer k, return the number of unique k-diff pairs in the array. A k-diff pair is an integer pair (nums[i], nums[j]), where the following are true: 0 <= i, j < nums.length i != j a <= b b - a == k Example 1: Input: nums = [3,1,4,1,5], k = 2 Output: 2 Exp... Read More

    #Medium#Array#Hash Table#Two Pointers#Binary Search#Sorting#Goldman Sachs#Microsoft#C++
  • Maximum Distance in Arrays

    Oct 02, 2020 About 1 min

    Given m arrays, and each array is sorted in ascending order. Now you can pick up two integers from two different arrays (each array picks one) and calculate the distance. We define the distance between two integers a and b to be their absolute difference |a-b|. Your task is to find the maximum distance. Example 1: Input: [[1,2,3], [4,5], [1,... Read More

    #Easy#Array#Hash Table#Yahoo#C++
  • [LeetCode October Challange] Day 2 - Combination Sum

    Oct 02, 2020 About 1 min

    Given an array of distinct integers candidates and a target integer target, return a list of all unique combinations of candidates where the chosen numbers sum to target. You may return the combinations in any order. The same number may be chosen from candidates an unlimited number of times. Two combinations are unique if the frequency of at le... Read More

    #Medium#Array#Backtracking#Amazon#Facebook#eBay#Uber#Microsoft#Apple#C++
  • [LeetCode October Challange] Day 1 - Number of Recent Calls

    Oct 01, 2020 About 1 min

    You have a RecentCounter class which counts the number of recent requests within a certain time frame. Implement the RecentCounter class: RecentCounter() Initializes the counter with zero recent requests. int ping(int t) Adds a new request at time t, where t represents some time in milliseconds, and returns the number of requests that has ... Read More

    #Easy#Design#Queue#Data Stream#Yandex#C++
  • Word Squares

    Sep 30, 2020 About 2 mins

    Given a set of words (without duplicates), find all word squares you can build from them. A sequence of words forms a valid word square if the k-th row and column read the exact same string, where 0 ≤ k < max(numRows, numColumns). For example, the word sequence ["ball","area","lead","lady"] forms a word square because each word reads the sa... Read More

    #Hard#Backtracking#Trie#Bloomberg#C++
  • [LeetCode September Challange]Day30-First Missing Positive

    Sep 30, 2020 About 1 min

    Given an unsorted integer array, find the smallest missing positive integer. Example 1: Input: [1,2,0] Output: 3 Example 2: Input: [3,4,-1,1] Output: 2 Example 3: Input: [7,8,9,11,12] Output: 1 Follow up: Your algorithm should run in O(n) time and uses constant extra space. Solution Time complexity : O(n) Space complexity : O(1) clas... Read More

    #Hard#Array#Hash Table#Amazon#Microsoft#Google#Databricks#Apple#Tesla#eBay#Uber#Bloomberg#ByteDance#Goldman Sachs#C++
  • [LeetCode September Challange]Day29-Word Break

    Sep 29, 2020 About 1 min

    Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words. Note: The same word in the dictionary may be reused multiple times in the segmentation. You may assume the dictionary does not contain duplicate words. ... Read More

    #Medium#Hash Table#String#Dynamic Programming#Trie#Memoization#Facebook#Amazon#Apple#Microsoft#Google#Bloomberg#Qualtrics#ByteDance#Twitter#Adobe#eBay#GoDaddy#C++
  • [LeetCode September Challange]Day28-Subarray Product Less Than K

    Sep 28, 2020 About 1 min

    Your are given an array of positive integers nums. Count and print the number of (contiguous) subarrays where the product of all the elements in the subarray is less than k. Example 1: Input: nums = [10, 5, 2, 6], k = 100 Output: 8 Explanation: The 8 subarrays that have product less than 100 are: [10], [5], [2], [6], [10, 5], [5, 2], [2, 6], [... Read More

    #Medium#Array#Sliding Window#Akuna Capital#Google#C++
  • [LeetCode September Challange]Day27-Evaluate Division

    Sep 27, 2020 About 3 mins

    You are given equations in the format A / B = k, where A and B are variables represented as strings, and k is a real number (floating-point number). Given some queries, return the answers. If the answer does not exist, return -1.0. The input is always valid. You may assume that evaluating the queries will result in no division by zero and there... Read More

    #Medium#Array#Depth-First-Search#Breadth-First-Search#Union Find#Graph#Amazon#Google#Bloomberg#Facebook#Microsoft#C++
  • [LeetCode September Challange]Day26-Teemo Attacking

    Sep 26, 2020 About 2 mins

    In LOL world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned condition. Now, given the Teemo’s attacking ascending time series towards Ashe and the poisoning time duration per Teemo’s attacking, you need to output the total time that Ashe is in poisoned condition. You may assume that Teemo attacks at the v... Read More

    #Medium#Array#Simulation#Riot Games#C++
  • Insert into a Sorted Circular Linked List

    Sep 26, 2020 About 2 mins

    Given a node from a Circular Linked List which is sorted in ascending order, write a function to insert a value insertVal into the list such that it remains a sorted circular list. The given node can be a reference to any single node in the list, and may not be necessarily the smallest value in the circular list. If there are multiple suitable ... Read More

    #Medium#Linked List#Facebook#Quip (Saleforce)#C++
  • [LeetCode September Challange]Day25-Largest Number

    Sep 25, 2020 About 1 min

    Given a list of non negative integers, arrange them such that they form the largest number. Example 1: Input: [10,2] Output: "210" Example 2: Input: [3,30,34,5,9] Output: "9534330" Note: The result may be very large, so you need to return a string instead of an integer. Solution Time complexity : O(nlogn) Space complexity : O(n) class ... Read More

    #Medium#String#Greedy#Sorting#Microsoft#Apple#Facebook#Amazon#Adobe#ByteDance#C++
  • [LeetCode September Challange]Day24-Find the Difference

    Sep 24, 2020 About 1 min

    Given two strings s and t which consist of only lowercase letters. String t is generated by random shuffling string s and then add one more letter at a random position. Find the letter that was added in t. Example: Input: s = "abcd" t = "abcde" Output: e Explanation: 'e' is the letter that was added. Solution Time complexity : O(n) Spa... Read More

    #Easy#Hash Table#String#Bit Manipulation#Sorting#Amazon#C++
  • [LeetCode September Challange]Day23-Gas Station

    Sep 23, 2020 About 2 mins

    There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to its next station (i+1). You begin the journey with an empty tank at one of the gas stations. Return the starting gas station’s index if you can travel... Read More

    #Medium#Array#Greedy#Amazon#Microsoft#Google#Uber#Apple#C++
  • [LeetCode September Challange]Day22-Majority Element II

    Sep 22, 2020 About 1 min

    Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. Note: The algorithm should run in linear time and in O(1) space. Example 1: Input: [3,2,3] Output: [3] Example 2: Input: [1,1,1,3,3,2,2,2] Output: [1,2] Solution Time complexity : O(n) Space complexity : O(1) class Solution { public: vector<... Read More

    #Medium#Array#Hash Table#Sorting#Counting#C++
  • Inorder Successor in BST II

    Sep 21, 2020 About 2 mins

    Given a node in a binary search tree, find the in-order successor of that node in the BST. If that node has no in-order successor, return null. The successor of a node is the node with the smallest key greater than node.val. You will have direct access to the node but not to the root of the tree. Each node will have a reference to its parent ... Read More

    #Medium#Tree#Microsoft#Quip(Salesforce)#C++
  • [LeetCode September Challange]Day21-Car Pooling

    Sep 21, 2020 About 1 min

    You are driving a vehicle that has capacity empty seats initially available for passengers. The vehicle only drives east (ie. it cannot turn around and drive west.) Given a list of trips, trip[i] = [num_passengers, start_location, end_location] contains information about the i-th trip: the number of passengers that must be picked up, and the l... Read More

    #Medium#Array#Sorting#Heap (Priority Queue)#Simulation#Prefix Sum#C++
  • [LeetCode September Challange]Day20-Unique Paths III

    Sep 20, 2020 About 2 mins

    On a 2-dimensional grid, there are 4 types of squares: 1 represents the starting square. There is exactly one starting square. 2 represents the ending square. There is exactly one ending square. 0 represents empty squares we can walk over. -1 represents obstacles that we cannot walk over. Return the number of 4-directional walks fr... Read More

    #Hard#Array#Backtracking#Bit Manipulation#Matrix#C++
  • [LeetCode September Challange]Day19-Sequential Digits

    Sep 19, 2020 About 1 min

    An integer has sequential digits if and only if each digit in the number is one more than the previous digit. Return a sorted list of all the integers in the range [low, high] inclusive that have sequential digits. Example 1: Input: low = 100, high = 300 Output: [123,234] Example 2: Input: low = 1000, high = 13000 Output: [1234,2345,3456,456... Read More

    #Medium#Enumeration#C++
  • [LeetCode September Challange]Day18-Best Time to Buy and Sell Stock

    Sep 18, 2020 About 1 min

    Say you have an array for which the i-th element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profit. Note that you cannot sell a stock before you buy one. Example 1: Input: [7,1,5,3,6,4] Output: 5... Read More

    #Easy#Array#Dynamic Programming#C++
  • [LeetCode September Challange]Day17-Robot Bounded In Circle

    Sep 17, 2020 About 1 min

    On an infinite plane, a robot initially stands at (0, 0) and faces north. The robot can receive one of three instructions: "G" : go straight 1 unit. "L" : turn 90 degrees to the left. "R" : turn 90 degress to the right. The robot performs the instructions given in order, and repeats them forever. Return true if and only if there exis... Read More

    #Medium#Math#String#Simulation#C++
  • [LeetCode September Challange]Day16-Maximum XOR of Two Numbers in an Array

    Sep 16, 2020 About 1 min

    Given an integer array nums, return the maximum result of nums[i] XOR nums[j], where 0 ≤ i ≤ j < n. Follow up: Could you do this in O(n) runtime? Example 1: Input: nums = [3,10,5,25,2,8] Output: 28 Explanation: The maximum result is 5 XOR 25 = 28. Example 2: Input: nums = [0] Output: 0 Example 3: Input: nums = [2,4] Output: 6 Example ... Read More

    #Medium#Array#Hash Table#Bit Manipulation#Trie#C++
  • [LeetCode September Challange]Day15-Length of Last Word

    Sep 15, 2020 About 1 min

    Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word (last word means the last appearing word if we loop from left to right) in the string. If the last word does not exist, return 0. Note: A word is defined as a maximal substring consisting of non-space characters only. Example... Read More

    #Easy#String#C++
  • [LeetCode September Challange]Day14-House Robber

    Sep 14, 2020 About 1 min

    You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and it will automatically contact the police if two adjacent houses were broken into on the same night. Given a l... Read More

    #Easy#Dynamic Programming#C++
  • [LeetCode September Challange]Day13-Insert Interval

    Sep 13, 2020 About 1 min

    Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary). You may assume that the intervals were initially sorted according to their start times. Example 1: Input: intervals = [[1,3],[6,9]], newInterval = [2,5] Output: [[1,5],[6,9]] Example 2: Input: intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]... Read More

    #Hard#Array#C++
  • [LeetCode September Challange]Day12-Combination Sum III

    Sep 12, 2020 About 1 min

    Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers. Note: All numbers will be positive integers. The solution set must not contain duplicate combinations. Example 1: Input: k = 3, n = 7 Output: [[1,2,4]] Example 2:... Read More

    #Medium#Array#Backtracking#C++
  • [LeetCode September Challange]Day11-Maximum Product Subarray

    Sep 11, 2020 About 1 min

    Given an integer array nums, find the contiguous subarray within an array (containing at least one number) which has the largest product. Example 1: Input: [2,3,-2,4] Output: 6 Explanation: [2,3] has the largest product 6. Example 2: Input: [-2,0,-1] Output: 0 Explanation: The result cannot be 2, because [-2,-1] is not a subarray. Solutio... Read More

    #Medium#Array#Dynamic Programming#C++
  • [LeetCode September Challange]Day10-Bulls and Cows

    Sep 10, 2020 About 1 min

    You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint that indicates how many digits in said guess match your secret number exactly in both digit and position (called “bulls”) and how many digits match th... Read More

    #Hash Table#String#Counting#C++
  • [LeetCode September Challange]Day9-Compare Version Numbers

    Sep 09, 2020 About 2 mins

    Compare two version numbers version1 and version2. If version1 > version2 return 1; if version1 < version2 return -1;otherwise return 0. You may assume that the version strings are non-empty and contain only digits and the . character. The . character does not represent a decimal point and is used to separate number sequences. For insta... Read More

    #Two Pointers#String#C++
  • 929. Unique Email Addresses

    Sep 08, 2020 About 1 min

    Every email consists of a local name and a domain name, separated by the @ sign. For example, in alice@leetcode.com, alice is the local name, and leetcode.com is the domain name. Besides lowercase letters, these emails may contain '.'s or '+'s. If you add periods ('.') between some characters in the local name part of an email address, mail s... Read More

    #Array#Hash Table#String#C++
  • [LeetCode September Challange]Day8-Sum of Root To Leaf Binary Numbers

    Sep 08, 2020 About 1 min

    Given a binary tree, each node has value 0 or 1. Each root-to-leaf path represents a binary number starting with the most significant bit. For example, if the path is 0 -> 1 -> 1 -> 0 -> 1, then this could represent 01101 in binary, which is 13. For all leaves in the tree, consider the numbers represented by the path from the root... Read More

    #Tree#Depth-First-Search#Binary Tree#C++
  • 157. Read N Characters Given Read4

    Sep 08, 2020 About 4 mins

    Given a file and assume that you can only read the file using a given method read4, implement a method to read n characters. Method read4: The API read4 reads 4 consecutive characters from the file, then writes those characters into the buffer array buf. The return value is the number of actual characters read. Note that read4() has its own ... Read More

    #String#C++
  • 346. Moving Average from Data Stream

    Sep 08, 2020 About 1 min

    Given a stream of integers and a window size, calculate the moving average of all integers in the sliding window. Example: MovingAverage m = new MovingAverage(3); m.next(1) = 1 m.next(10) = (1 + 10) / 2 m.next(3) = (1 + 10 + 3) / 3 m.next(5) = (10 + 3 + 5) / 3 Solution Time complexity : O(1) Space complexity : O(n) class MovingAverage { p... Read More

    #Design#Queue#C++
  • [LeetCode September Challange]Day7-Word Pattern

    Sep 07, 2020 About 1 min

    Given a pattern and a string str, find if str follows the same pattern. Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str. Example 1: Input: pattern = "abba", str = "dog cat cat dog" Output: true Example 2: Input:pattern = "abba", str = "dog cat cat fish" Output: false Ex... Read More

    #Hash Table#String#C++
  • [LeetCode September Challange]Day6-Image Overlap

    Sep 06, 2020 About 1 min

    Two images A and B are given, represented as binary, square matrices of the same size. (A binary matrix has only 0s and 1s as values.) We translate one image however we choose (sliding it left, right, up, or down any number of units), and place it on top of the other image. After, the overlap of this translation is the number of positions tha... Read More

    #Array#Matrix#C++
  • [LeetCode September Challange]Day5-All Elements in Two Binary Search Trees

    Sep 05, 2020 About 1 min

    Given two binary search trees root1 and root2. Return a list containing all the integers from both trees sorted in ascending order. Example 1: Input: root1 = [2,1,4], root2 = [1,0,3] Output: [0,1,1,2,3,4] Example 2: Input: root1 = [0,-10,10], root2 = [5,1,7,0,2] Output: [-10,0,0,1,2,5,7,10] Example 3: Input: root1 = [], root2 = [5,1,7,0,... Read More

    #Tree#Depth-First-Search#Binary Search Tree#Sorting#Binary Tree#C++
  • [LeetCode September Challange]Day4-Partition Labels

    Sep 04, 2020 About 1 min

    A string S of lowercase English letters is given. We want to partition this string into as many parts as possible so that each letter appears in at most one part, and return a list of integers representing the size of these parts. Example 1: Input: S = "ababcbacadefegdehijhklij" Output: [9,7,8] Explanation: The partition is "ababcbaca", "defegd... Read More

    #Hash Table#Two Pointers#String#Greedy#C++
  • [LeetCode September Challange]Day3-Repeated Substring Pattern

    Sep 03, 2020 About 1 min

    Given a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. You may assume the given string consists of lowercase English letters only and its length will not exceed 10000. Example 1: Input: "abab" Output: True Explanation: It's the substring "ab" twice. Example ... Read More

    #String#String Matching#C++
  • [LeetCode September Challange]Day2-Contains Duplicate III

    Sep 02, 2020 About 1 min

    Given an array of integers, find out whether there are two distinct indices i and j in the array such that the absolute difference between nums[i] and nums[j] is at most t and the absolute difference between i and j is at most k. Example 1: Input: nums = [1,2,3,1], k = 3, t = 0 Output: true Example 2: Input: nums = [1,0,1,1], k = 1, t = 2 Out... Read More

    #Array#Sliding Window#Sorting#Bucket Sort#Ordered Set#C++
  • [LeetCode September Challange]Day1-Largest Time for Given Digits

    Sep 01, 2020 About 1 min

    Given an array of 4 digits, return the largest 24 hour time that can be made. The smallest 24 hour time is 00:00, and the largest is 23:59. Starting from 00:00, a time is larger if more time has elapsed since midnight. Return the answer as a string of length 5. If no valid time can be made, return an empty string. Example 1: Input: [1,2,3,4... Read More

    #String#Enumeration#C++
  • [LeetCode August Challange]Day31-Delete Node in a BST

    Aug 31, 2020 About 2 mins

    Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of the BST. Basically, the deletion can be divided into two stages: Search for a node to remove. If the node is found, delete the node. Note: Time complexity should be O(height of tree). Exampl... Read More

    #Tree#Binary Search Tree#Binary Tree#C++
  • [LeetCode August Challange]Day30-Largest Component Size by Common Factor

    Aug 30, 2020 About 1 min

    Given a non-empty array of unique positive integers A, consider the following graph: There are A.length nodes, labelled A[0] to A[A.length - 1]; There is an edge between A[i] and A[j] if and only if A[i] and A[j] share a common factor greater than 1. Return the size of the largest connected component in the graph. Example 1: Input: [4,... Read More

    #Array#Math#Union Find#C++
  • [LeetCode August Challange]Day29-Pancake Sorting

    Aug 29, 2020 About 2 mins

    Given an array of integers A, We need to sort the array performing a series of pancake flips. In one pancake flip we do the following steps: Choose an integer k where 0 <= k < A.length. Reverse the sub-array A[0...k]. For example, if A = [3,2,1,4] and we performed a pancake flip choosing k = 2</font>**, we reverse the sub-array... Read More

    #Array#Two Pointers#Greedy#Sorting#C++
  • [LeetCode August Challange]Day28-Implement Rand10() Using Rand7()

    Aug 28, 2020 About 1 min

    Given the API rand7 which generates a uniform random integer in the range 1 to 7, write a function rand10 which generates a uniform random integer in the range 1 to 10. You can only call the API rand7 and you shouldn’t call any other API. Please don’t use the system’s Math.random(). Notice that Each test case has one argument n, the number of t... Read More

    #Math#Rejection Sampling#Randomized#Probability and Statistics#C++
  • [LeetCode August Challange]Day27-Find Right Interval

    Aug 27, 2020 About 2 mins

    Given a set of intervals, for each of the interval i, check if there exists an interval j whose start point is bigger than or equal to the end point of the interval i, which can be called that j is on the “right” of i. For any interval i, you need to store the minimum interval j’s index, which means that the interval j has the minimum start poi... Read More

    #Array#Binary Search#Sorting#C++
  • [LeetCode August Challange]Day26-Fizz Buzz

    Aug 26, 2020 About 1 min

    Write a program that outputs the string representation of numbers from 1 to n. But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. For numbers which are multiples of both three and five output “FizzBuzz”. Example: n = 15, Return: [ "1", "2", "Fizz", "4", "Bu... Read More

    #Math#String#Simulation#C++
  • [LeetCode August Challange]Day25-Minimum Cost For Tickets

    Aug 25, 2020 About 2 mins

    In a country popular for train travel, you have planned some train travelling one year in advance. The days of the year that you will travel is given as an array days. Each day is an integer from 1 to 365. Train tickets are sold in 3 different ways: a 1-day pass is sold for costs[0] dollars; a 7-day pass is sold for costs[1] dollars; a... Read More

    #Array#Dynamic Programming#C++
  • [LeetCode August Challange]Day24-Sum of Left Leaves

    Aug 24, 2020 About 1 min

    Find the sum of all left leaves in a given binary tree. Example: 3 / \ 9 20 / \ 15 7 There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24. Solution Time complexity : O(n) Space complexity : O(n) /** * Definition for a binary tree node. * struct TreeNode { * int val; * ... Read More

    #Tree#Depth-First-Search#Breadth-First-Search#Binary Tree#C++
  • [LeetCode August Challange]Day23-Stream of Characters

    Aug 23, 2020 About 1 min

    Implement the StreamChecker class as follows: StreamChecker(words): Constructor, init the data structure with the given words. query(letter): returns true if and only if for some k >= 1, the last k characters queried (in order from oldest to newest, including this letter just queried) spell one of the words in the given list. Example:... Read More

    #Array#String#Design#Trie#Data Stream#C++
  • [LeetCode August Challange]Day22-Random Point in Non-overlapping Rectangles

    Aug 22, 2020 About 2 mins

    Given a list of non-overlapping axis-aligned rectangles rects, write a function pick which randomly and uniformily picks an integer point in the space covered by the rectangles. Note: An integer point is a point that has integer coordinates. A point on the perimeter of a rectangle is included in the space covered by the rectangles. i-th ... Read More

    #Math#Binary Search#Reservoir Sampling#Prefix Sum#Ordered Set#Randomized#C++
  • [LeetCode August Challange]Day21-Sort Array By Parity

    Aug 21, 2020 About 1 min

    Given an array A of non-negative integers, return an array consisting of all the even elements of A, followed by all the odd elements of A. You may return any answer array that satisfies this condition. Example 1: Input: [3,1,2,4] Output: [2,4,3,1] The outputs [4,2,3,1], [2,4,1,3], and [4,2,1,3] would also be accepted. Note: 1 <= A.len... Read More

    #Array#Two Pointers#Sorting#C++
  • [LeetCode August Challange]Day20-Reorder List

    Aug 20, 2020 About 1 min

    Given a singly linked list L: L0→L1→…→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You may not modify the values in the list’s nodes, only nodes itself may be changed. Example 1: Given 1->2->3->4, reorder it to 1->4->2->3. Example 2: Given 1->2->3->4->5, reorder it to 1->5->2->4->3. Solution ... Read More

    #Linked List#Two Pointers#Stack#Recursion#C++
  • [LeetCode August Challange]Day19-Goat Latin

    Aug 19, 2020 About 1 min

    A sentence S is given, composed of words separated by spaces. Each word consists of lowercase and uppercase letters only. We would like to convert the sentence to “Goat Latin” (a made-up language similar to Pig Latin.) The rules of Goat Latin are as follows: If a word begins with a vowel (a, e, i, o, or u), append "ma" to the end of the word.... Read More

    #String#C++
  • [LeetCode August Challange]Day18-Numbers With Same Consecutive Differences

    Aug 18, 2020 About 1 min

    Return all non-negative integers of length N such that the absolute difference between every two consecutive digits is K. Note that every number in the answer must not have leading zeros except for the number 0 itself. For example, 01 has one leading zero and is invalid, but 0 is valid. You may return the answer in any order. Example 1: Input... Read More

    #Backtracking#Breadth-First-Search#C++
  • [LeetCode August Challange]Day17-Distribute Candies to People

    Aug 17, 2020 About 2 mins

    We distribute some number of candies, to a row of n = num_people people in the following way: We then give 1 candy to the first person, 2 candies to the second person, and so on until we give n candies to the last person. Then, we go back to the start of the row, giving n + 1 candies to the first person, n + 2 candies to the second person, and... Read More

    #Math#Simulation#C++
  • [LeetCode August Challange]Day16-Best Time to Buy and Sell Stock III

    Aug 16, 2020 About 2 mins

    Say you have an array for which the i-th element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete at most two transactions. Note: You may not engage in multiple transactions at the same time (i.e., you must sell the stock before you buy again). Example 1: Input: [3,3,5,0,0,3,1,4] Output:... Read More

    #Array#Dynamic Programming#C++
  • [LeetCode August Challange]Day15-Non-overlapping Intervals

    Aug 15, 2020 About 1 min

    Given a collection of intervals, find the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping. Example 1: Input: [[1,2],[2,3],[3,4],[1,3]] Output: 1 Explanation: [1,3] can be removed and the rest of intervals are non-overlapping. Example 2: Input: [[1,2],[1,2],[1,2]] Output: 2 Explanation: You need... Read More

    #Array#Dynamic Programming#Greedy#Sorting#C++
  • [LeetCode August Challange]Day14-Longest Palindrome

    Aug 14, 2020 About 1 min

    Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters. This is case sensitive, for example "Aa" is not considered a palindrome here. Note: Assume the length of given string will not exceed 1,010. Example: Input: "abccccdd" Output: 7 Explanation: One ... Read More

    #Hash Table#String#Greedy#C++
  • [LeetCode August Challange]Day13-Iterator for Combination

    Aug 13, 2020 About 1 min

    Design an Iterator class, which has: A constructor that takes a string characters of sorted distinct lowercase English letters and a number combinationLength as arguments. A function next() that returns the next combination of length combinationLength in lexicographical order. A function hasNext() that returns True if and only if there e... Read More

    #String#Backtracking#Design#Iterator#C++
  • [LeetCode August Challange]Day12-Pascal's Triangle II

    Aug 12, 2020 About 1 min

    Given a non-negative index k where k ≤ 33, return the k-th index row of the Pascal’s triangle. Note that the row index starts from 0. In Pascal’s triangle, each number is the sum of the two numbers directly above it. Example: Input: 3 Output: [1,3,3,1] Follow up: Could you optimize your algorithm to use only O(k) extra space? solution ... Read More

    #Array#Dynamic Programming#C++
  • [LeetCode August Challange]Day11-H-Index

    Aug 11, 2020 About 1 min

    Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher’s h-index. According to the definition of h-index on Wikipedia: “A scientist has index h if h of his/her N papers have at least h citations each, and the other N − h papers have no more than h citations each.” Examp... Read More

    #Array#Sorting#Counting Sort#C++
  • [LeetCode August Challange]Day10-Excel Sheet Column Number

    Aug 10, 2020 About 1 min

    Given a column title as appear in an Excel sheet, return its corresponding column number. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... Example 1: Input: "A" Output: 1 Example 2: Input: "AB" Output: 28 Example 3: Input: "ZY" Output: 701 Constraints: 1 <= s.length <= 7 s consists only ... Read More

    #Math#String#C++
  • [LeetCode August Challange]Day9-Rotting Oranges

    Aug 09, 2020 About 2 mins

    In a given grid, each cell can have one of three values: the value 0 representing an empty cell; the value 1 representing a fresh orange; the value 2 representing a rotten orange. Every minute, any fresh orange that is adjacent (4-directionally) to a rotten orange becomes rotten. Return the minimum number of minutes that must elapse u... Read More

    #Array#Breadth-First-Search#Matrix#C++
  • [LeetCode August Challange]Day8-Path Sum III

    Aug 08, 2020 About 2 mins

    You are given a binary tree in which each node contains an integer value. Find the number of paths that sum to a given value. The path does not need to start or end at the root or a leaf, but it must go downwards (traveling only from parent nodes to child nodes). The tree has no more than 1,000 nodes and the values are in the range -1,000,000... Read More

    #Tree#Depth-First-Search#Binary Tree#C++
  • [LeetCode August Challange]Day7-Vertical Order Traversal of a Binary Tree

    Aug 07, 2020 About 2 mins

    Given a binary tree, return the vertical order traversal of its nodes values. For each node at position (X, Y), its left and right children respectively will be at positions (X-1, Y-1) and (X+1, Y-1). Running a vertical line from X = -infinity to X = +infinity, whenever the vertical line touches some nodes, we report the values of the nodes in... Read More

    #Hash Table#Tree#Depth-First-Search#Breadth-First-Search#Binary Tree#C++
  • [LeetCode August Challange]Day6-Find All Duplicates in an Array

    Aug 06, 2020 About 1 min

    Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. Find all the elements that appear twice in this array. Could you do it without extra space and in O(n) runtime? Example: Input: [4,3,2,7,8,2,3,1] Output: [2,3] solution Time complexity : O(n) Space complexity : O(1) class So... Read More

    #Array#Hash Table#C++
  • [LeetCode August Challange]Day5-Add and Search Word - Data structure design

    Aug 05, 2020 About 1 min

    Design a data structure that supports the following two operations: void addWord(word) bool search(word) search(word) can search a literal word or a regular expression string containing only letters a-z or .. A . means it can represent any one letter. Example: addWord("bad") addWord("dad") addWord("mad") search("pad") -> false search("bad... Read More

    #String#Depth-First-Search#Design#Trie#C++
  • [LeetCode August Challange]Day4-Power of Four

    Aug 04, 2020 About 1 min

    Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example 1: Input: 16 Output: true Example 2: Input: 5 Output: false Follow up: Could you solve it without loops/recursion? solution Time complexity : O(1) Space complexity : O(1) class Solution { public: bool isPowerOfFour(int num) { re... Read More

    #Math#Bit Manipulation#Recursion#C++
  • [LeetCode August Challange]Day3-Valid Palindrome

    Aug 03, 2020 About 1 min

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. Note: For the purpose of this problem, we define empty string as valid palindrome. Example 1: Input: "A man, a plan, a canal: Panama" Output: true Example 2: Input: "race a car" Output: false Constraints: s consists only of prin... Read More

    #Two Pointers#String#C++
  • [LeetCode August Challange]Day2-Design HashSet

    Aug 02, 2020 About 1 min

    Design a HashSet without using any built-in hash table libraries. To be specific, your design should include these functions: add(value): Insert a value into the HashSet. contains(value): Return whether the value exists in the HashSet or not. remove(value): Remove a value in the HashSet. If the value does not exist in the HashSet, do no... Read More

    #Array#Hash Table#Linked List#Design#Hash Function#C++
  • [LeetCode August Challange]Day1-Detect Capital

    Aug 01, 2020 About 1 min

    Given a word, you need to judge whether the usage of capitals in it is right or not. We define the usage of capitals in a word to be right when one of the following cases holds: All letters in this word are capitals, like “USA”. All letters in this word are not capitals, like “leetcode”. Only the first letter in this word is capital, li... Read More

    #String#C++
  • [LeetCode July Challange]Day31-Climbing Stairs

    Jul 31, 2020 About 1 min

    You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? Example 1: Input: 2 Output: 2 Explanation: There are two ways to climb to the top. 1. 1 step + 1 step 2. 2 steps Example 2: Input: 3 Output: 3 Explanation: There are three ways ... Read More

    #Math#Dynamic Programming#Memoization#C++
  • [LeetCode July Challange]Day30-Word Break II

    Jul 30, 2020 About 1 min

    Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences. Note: The same word in the dictionary may be reused multiple times in the segmentation. You may assume the dictionary does not con... Read More

    #Hash Table#String#Dynamic Programming#Backtracking#Trie#Memoization#C++
  • [LeetCode July Challange]Day29-Best Time to Buy and Sell Stock with Cooldown

    Jul 29, 2020 About 1 min

    Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times) with the following restrictions: You may not engage in multiple transactions at the same time (... Read More

    #Array#Dynamic Programming#C++
  • [LeetCode July Challange]Day28-Task Scheduler

    Jul 28, 2020 About 3 mins

    You are given a char array representing tasks CPU need to do. It contains capital letters A to Z where each letter represents a different task. Tasks could be done without the original order of the array. Each task is done in one unit of time. For each unit of time, the CPU could complete either one task or just be idle. However, there is a non... Read More

    #Array#Hash Table#Greedy#Sorting#Heap (Priority Queue)#Counting#C++
  • [LeetCode July Challange]Day27-Construct Binary Tree from Inorder and Postorder Traversal

    Jul 27, 2020 About 1 min

    Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. For example, given inorder = [9,3,15,20,7] postorder = [9,15,7,20,3] return the following binary tree: 3 / \ 9 20 / \ 15 7 solution time complexity : O(nlogn) space complexity : ... Read More

    #Array#Hash Table#Divide and Conquer#Tree#Binary Tree#C++
  • [LeetCode July Challange]Day26-Add Digits

    Jul 26, 2020 About 1 min

    Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. Example 1: Input: 38 Output: 2 Explanation: The process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, return it. Follow up: Could you do it without any loop/recursion in O(1) runtime? solution time complexity : ... Read More

    #Math#Simulation#Number Theory#C++
  • [LeetCode July Challange]Day25-Find Minimum in Rotated Sorted Array II

    Jul 25, 2020 About 1 min

    Suppose an array sorted in ascending order 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]). Find the minimum element. The array may contain duplicates. Example 1: Input: [1,3,5] Output: 1 Example 2: Input: [2,2,2,0,1] Output: 0 Note: This is a follow up problem to Find Minimum... Read More

    #Array#Binary Search#C++
  • [LeetCode July Challange]Day24-All Paths From Source to Target

    Jul 24, 2020 About 1 min

    Given a directed, acyclic graph of N nodes. Find all possible paths from node 0 to node N-1, and return them in any order. The graph is given as follows: the nodes are 0, 1, …, graph.length - 1. graph[i] is a list of all nodes j for which the edge (i, j) exists. Example: Input: [[1,2], [3], [3], []] Output: [[0,1,3],[0,2,3]] Explanation: ... Read More

    #Backtracking#Depth-First-Search#Breadth-First-Search#Graph#C++
  • [LeetCode July Challange]Day23-Single Number III

    Jul 23, 2020 About 1 min

    Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. Example: Input: [1,2,1,3,2,5] Output: [3,5] Note: The order of the result is not important. So in the above example, [5, 3] is also correct. Your algorithm should ru... Read More

    #Array#Bit Manipulation#C++
  • [LeetCode July Challange]Day22-Binary Tree Zigzag Level Order Traversal

    Jul 22, 2020 About 1 min

    Given a binary tree, return the zigzag level order traversal of its nodes’ values. (ie, from left to right, then right to left for the next level and alternate between). For example: Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 return its zigzag level order traversal as: [ [3], [20,9], [15,7] ] ... Read More

    #Tree#Breadth-First-Search#Binary Tree#C++
  • [LeetCode July Challange]Day21-Word Search

    Jul 21, 2020 About 1 min

    Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once. Example: board = [ ['A','B','C','E'], ['S','F','C','S'], ['A','D','E','E'] ... Read More

    #Array#Backtracking#Matrix#C++
  • [LeetCode July Challange]Day20-Remove Linked List Elements

    Jul 20, 2020 About 1 min

    Remove all elements from a linked list of integers that have value val. Example: Input: 1->2->6->3->4->5->6, val = 6 Output: 1->2->3->4->5 solution time complexity : O(n) space complexity : O(1) /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNo... Read More

    #Linked List#Recursion#C++
  • [LeetCode July Challange]Day19-Add Binary

    Jul 19, 2020 About 1 min

    Given two binary strings, return their sum (also a binary string). The input strings are both non-empty and contains only characters 1 or 0. Example 1: Input: a = "11", b = "1" Output: "100" Example 2: Input: a = "1010", b = "1011" Output: "10101" Constraints: Each string consists only of ‘0’ or ‘1’ characters. 1 <= a.length, b.len... Read More

    #Math#String#Bit Manipulation#Simulation#C++
  • [LeetCode July Challange]Day18-Course Schedule II

    Jul 18, 2020 About 2 mins

    There are a total of n courses you have to take, labeled from 0 to n-1. Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pair: [0,1] Given the total number of courses and a list of prerequisite pairs, return the ordering of courses you should take to finish all courses. ... Read More

    #Depth-First-Search#Breadth-First-Search#Graph#Topological Sort#C++
  • [LeetCode July Challange]Day17-Top K Frequent Elements

    Jul 17, 2020 About 1 min

    Given a non-empty array of integers, return the k most frequent elements. Example 1: Input: nums = [1,1,1,2,2,3], k = 2 Output: [1,2] Example 2: Input: nums = [1], k = 1 Output: [1] Note: You may assume k is always valid, 1 ≤ k ≤ number of unique elements. Your algorithm’s time complexity must be better than O(n log n), where n is the ... Read More

    #Array#Hash Table#Divide and Conquer#Sorting#Heap (Priority Queue)#Bucket Sort#Counting#Quickselect#C++
  • [LeetCode July Challange]Day16-Pow(x, n)

    Jul 16, 2020 About 1 min

    Implement pow(x, n), which calculates x raised to the power n (xn). Example 1: Input: 2.00000, 10 Output: 1024.00000 Example 2: Input: 2.10000, 3 Output: 9.26100 Example 3: Input: 2.00000, -2 Output: 0.25000 Explanation: 2-2 = 1/22 = 1/4 = 0.25 Note: -100.0 < x < 100.0 n is a 32-bit signed integer, within the range [−231, 231 −... Read More

    #Math#Recursion#C++
  • [LeetCode July Challange]Day15-Reverse Words in a String

    Jul 15, 2020 About 2 mins

    Given an input string, reverse the string word by word. Example 1: Input: "the sky is blue" Output: "blue is sky the" Example 2: Input: " hello world! " Output: "world! hello" Explanation: Your reversed string should not contain leading or trailing spaces. Example 3: Input: "a good example" Output: "example good a" Explanation: You need... Read More

    #Two Pointers#String#C++
  • [LeetCode July Challange]Day14-Angle Between Hands of a Clock

    Jul 14, 2020 About 1 min

    Given two numbers, hour and minutes. Return the smaller angle (in degrees) formed between the hour and the minute hand. Example 1: Input: hour = 12, minutes = 30 Output: 165 Example 2: Input: hour = 3, minutes = 30 Output: 75 Example 3: Input: hour = 3, minutes = 15 Output: 7.5 Example 4: Input: hour = 4, minutes = 50 Output: 155 ... Read More

    #Math#C++
  • [LeetCode July Challange]Day13-Same Tree

    Jul 13, 2020 About 1 min

    Given two binary trees, write a function to check if they are the same or not. Two binary trees are considered the same if they are structurally identical and the nodes have the same value. Example 1: Input: 1 1 / \ / \ 2 3 2 3 [1,2,3], [1,2,3] Output: true Example 2: Input: 1 ... Read More

    #Tree#Depth-First-Search#Breadth-First-Search#Binary Tree#C++
  • [LeetCode July Challange]Day12-Reverse Bits

    Jul 12, 2020 About 1 min

    Reverse bits of a given 32 bits unsigned integer. Example 1: Input: 00000010100101000001111010011100 Output: 00111001011110000010100101000000 Explanation: The input binary string 00000010100101000001111010011100 represents the unsigned integer 43261596, so return 964176192 which its binary representation is 00111001011110000010100101000000. E... Read More

    #Divide and Conquer#Bit Manipulation#C++
  • [LeetCode July Challange]Day11-Subsets

    Jul 11, 2020 About 1 min

    Given a set of distinct integers, nums, return all possible subsets (the power set). Note: The solution set must not contain duplicate subsets. Example : Input: nums = [1,2,3] Output: [ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], [] ] solution time complexity : O(2^n) space complexity : O(2^n) (n : nums size) class Soluti... Read More

    #Array#Backtracking#Bit Manipulation#C++
  • [LeetCode July Challange]Day10-Flatten a Multilevel Doubly Linked List

    Jul 10, 2020 About 2 mins

    You are given a doubly linked list which in addition to the next and previous pointers, it could have a child pointer, which may or may not point to a separate doubly linked list. These child lists may have one or more children of their own, and so on, to produce a multilevel data structure, as shown in the example below. Flatten the list so th... Read More

    #Linked List#Depth-First-Search#Doubly-Linked List#C++
  • [LeetCode July Challange]Day9-Maximum Width of Binary Tree

    Jul 09, 2020 About 2 mins

    Given a binary tree, write a function to get the maximum width of the given tree. The width of a tree is the maximum width among all levels. The binary tree has the same structure as a full binary tree, but some nodes are null. The width of one level is defined as the length between the end-nodes (the leftmost and right most non-null nodes in t... Read More

    #Tree#Depth-First-Search#Breadth-First-Search#Binary Tree#C++
  • [LeetCode July Challange]Day8-3Sum

    Jul 08, 2020 About 1 min

    Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. Note: The solution set must not contain duplicate triplets. Example: Given array nums = [-1, 0, 1, 2, -1, -4], A solution set is: [ [-1, 0, 1], [-1, -1, 2] ] solution time co... Read More

    #Array#Two Pointers#Sorting#C++
  • [LeetCode July Challange]Day7-Island Perimeter

    Jul 07, 2020 About 1 min

    You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completely surrounded by water, and there is exactly one island (i.e., one or more connected land cells). The island doesn’t have “lakes” (water inside that... Read More

    #Array#Depth-First-Search#Breadth-First-Search#Matrix#C++
  • [LeetCode July Challange]Day6-Plus One

    Jul 06, 2020 About 1 min

    Given a non-empty array of digits representing a non-negative integer, plus one to the integer. The digits are stored such that the most significant digit is at the head of the list, and each element in the array contain a single digit. You may assume the integer does not contain any leading zero, except the number 0 itself. Example 1: Input:... Read More

    #Array#Math#C++
  • [LeetCode July Challange]Day5-Hamming Distance

    Jul 05, 2020 About 1 min

    The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Given two integers x and y, calculate the Hamming distance. Note : 0 <= x, y <= 2^31. Example : Input: x = 1, y = 4 Output: 2 Explanation: 1 (0 0 0 1) 4 (0 1 0 0) ↑ ↑ The above arrows poi... Read More

    #Bit Manipulation#C++
  • [LeetCode July Challange]Day4-Ugly Number II

    Jul 04, 2020 About 1 min

    Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. Example 1: Input: n = 10 Output: 12 Explanation: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first 10 ugly numbers. Note : 1 is typically treated as an ugly number. n does not exceed 1690. Hint : ... Read More

    #Hash Table#Math#Dynamic Programming#Heap (Priority Queue)#C++
  • [LeetCode July Challange]Day3-Prison Cells After N Days

    Jul 03, 2020 About 2 mins

    There are 8 prison cells in a row, and each cell is either occupied or vacant. Each day, whether the cell is occupied or vacant changes according to the following rules: If a cell has two adjacent neighbors that are both occupied or both vacant, then the cell becomes occupied. Otherwise, it becomes vacant. (Note that because the prison is... Read More

    #Array#Hash Table#Math#Bit Manipulation#C++
  • [LeetCode July Challange]Day2-Binary Tree Level Order Traversal II

    Jul 02, 2020 About 1 min

    Given a binary tree, return the bottom-up level order traversal of its nodes’ values. (ie, from left to right, level by level from leaf to root). For example: Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 return its bottom-up level order traversal as: [ [15,7], [9,20], [3] ] ... Read More

    #Tree#Breadth-First-Search#Binary Tree#C++
  • [LeetCode July Challange]Day1-Arranging Coins

    Jul 01, 2020 About 1 min

    You have a total of n coins that you want to form in a staircase shape, where every k-th row must have exactly k coins. Given n, find the total number of full staircase rows that can be formed. n is a non-negative integer and fits within the range of a 32-bit signed integer. example 1 n = 5 The coins can form the following rows: ¤ ¤ ¤... Read More

    #Math
  • MQTT with wemos & win10

    Oct 14, 2019 About 1 min

    About MQTT Get started with Wemos D1 R2 Mosquitto (MQTT broker) Make sure the service named Mosquitto Broker is running on your computer. mosquitto_sub -h “localhost” (-p “9487” -u “username” -P “pwd”) -t “topic/#” (-d) mosquitto_pub -h “localhost” (-p “9487” -u “username” -P “pwd”) -m “Publishing Message” -t “topic/” PubSubClient (arduino ... Read More

    #MQTT#Arduino
  • Q-learning

    Aug 05, 2019 About 1 min

    Reinforcement Learning From A to Z by repeat again and again. Bellman Equation Learning from a reward after an action at a state in an environment. s : state a : action R : Reward V : Value : discount Markov Decision Process(MDP) Deterministic Search 100% chances take the action we want. Non-Deterministic Search not 100% chances take the ac... Read More

    #Q-learning
  • Win 10 & VM Ubuntu 18.04 - shared folder

    Jun 26, 2019 About 1 min

    VMware tools Reinstall VMware tools Copy & tar VMware tools Install VMware tools VMware settings VMware settings Set shared folder Mount shared folder Mount shared folder Read More

    #VirtualBox#Ubuntu
  • vscode with c++ Windows setup

    Apr 14, 2019 About 5 mins

    Download & Install Visual Studio Code Download & Install MinGW-w64 Modify “Architecture” in Settings Modify “Destination folder” in Installation folder others default is fine Download & Install LLVM Download “Pre-Built Binaries” version Modify “system PATH” option Modify “Destination Folder” Copy data Copy data in “C:\mingw-w64\... Read More

    #VScode#C++
  • SQL note

    Mar 26, 2019 About 18 mins

    Intro SQL = Structured Query Language SQL lets you access and manipulate databases Syntax SQL keywords are NOT case sensitive : select is the same as SELECT. -- 抓出所有資料 SELECT * FROM table_name; Some of The Most Important SQL Commands : Commands Discription SELECT extracts data from a data... Read More

    #SQL
  • python note

    Mar 22, 2019 About 8 mins

    一切都從這裡開始 if __name__ == '__main__': # 開始你想做的事, python以縮排當作'{}', 句尾不用加';' print("Hello Python") # 宣告變數,直接給值即可 x = 5 # 自動轉型為int y = "Shawn" # 自動轉型為str # 也可強制轉型 z = float("2") # z = 2.0 a = str(123) # a = "123" Function相關 # 宣告function def function_name(arg1, arg2, arg3 = default_value): # 做function該做的事 return (arg1 + arg2) # la... Read More

    #python
  • tennis game

    Mar 15, 2019 About 2 mins

    使用JavaScript製作的簡單小遊戲,簡單的AI。 玩家利用「滑鼠」控制「左方」檔板。 「三分」為勝負判定。 Read More

    #JavaScript
  • All272
  • HTB 10
  • LeetCode 242
  • Linux 2
  • Project 1
  • misc 1
  • note 16
Related Articles
TOC
Unpublished Work © 2017-2022 Shawn.Yang
Powered by Jekyll & Yat Theme.
Subscribe via RSS