Cell Complete

Cell compete: Eight houses, represented as a cells, are arranged as a straight line. Each days every cells competes with adjacent cells. An integer value 1 represents an active cell and a value of 0 represent an inactive cell. if the neigbour on both the sides of the cell are both active or inactive, the cell become inactive in the next day, otherwise the become active. The two cells on each or have a single adjacent cell, so asume that the onoccupied space in the opposite side is an inactive cell....

<span title='2020-06-26 00:00:00 +0000 UTC'>June 26, 2020</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

763. Partition Labels

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. 1 2 3 4 5 6 7 8 Example 1: Input: s = "ababcbacadefegdehijhklij" Output: [9,7,8] Explanation: The partition is "ababcbaca", "defegde", "hijhklij". This is a partition so that each letter appears in at most one part....

<span title='2020-06-24 00:00:00 +0000 UTC'>June 24, 2020</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

House Robber II

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 security system connected and it will automatically contact the police if two adjacent houses were broken into on the same night. Given a list of non-negative integers representing the amount of money of each house, determine the maximum amount of money you can rob tonight without alerting the police....

<span title='2020-06-23 00:00:00 +0000 UTC'>June 23, 2020</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

Max consecutive ones III

Given an array A of 0s and 1s, we may change up to K values from 0 to 1. Return the length of the longest (contiguous) subarray that contains only 1s. Example 1: 1 2 3 4 5 Input: A = [1,1,1,0,0,0,1,1,1,1,0], K = 2 Output: 6 Explanation: [1,1,1,0,0,1,1,1,1,1,1] Bolded numbers were flipped from 0 to 1. The longest subarray is underlined. Example 2: 1 2 3 4 5 Input: A = [0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,1,1,1,1], K = 3 Output: 10 Explanation: [0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1] Bolded numbers were flipped from 0 to 1....

<span title='2020-06-23 00:00:00 +0000 UTC'>June 23, 2020</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;volyx

Insert delete get random O(1)

Design a data structure that supports all following operations in average O(1) time. insert(val): Inserts an item val to the set if not already present. remove(val): Removes an item val from the set if present. getRandom: Returns a random element from current set of elements. Each element must have the same probability of being returned. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Example: // Init an empty set....

<span title='2020-06-22 00:00:00 +0000 UTC'>June 22, 2020</span>&nbsp;·&nbsp;4 min&nbsp;·&nbsp;volyx

Sort Colors

Given an array with n objects colored red, white or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white and blue. Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively. Note: You are not suppose to use the library’s sort function for this problem. Example: 1 2 Input: [2,0,2,1,1,0] Output: [0,0,1,1,2,2] Follow up:...

<span title='2020-06-20 00:00:00 +0000 UTC'>June 20, 2020</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

Unique Binary Search Trees

Given n, how many structurally unique BST’s (binary search trees) that store values 1 … n? Example: 1 2 3 4 5 6 7 8 9 10 Input: 3 Output: 5 Explanation: Given n = 3, there are a total of 5 unique BST's: 1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / \ \ 2 1 2 3 Notes: Catalan’s numbers:...

<span title='2020-06-19 00:00:00 +0000 UTC'>June 19, 2020</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;volyx

Maximum Sum Circular Subarray

Given a circular array C of integers represented by A, find the maximum possible sum of a non-empty subarray of C. Here, a circular array means the end of the array connects to the beginning of the array. (Formally, C[i] = A[i] when 0 <= i < A.length, and C[i+A.length] = C[i] when i >= 0.) Also, a subarray may only include each element of the fixed buffer A at most once....

<span title='2020-06-18 00:00:00 +0000 UTC'>June 18, 2020</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

Power of two

Given an integer, write a function to determine if it is a power of two. Example 1: 1 2 3 Input: 1 Output: true Explanation: 20 = 1 Example 2: 1 2 3 Input: 16 Output: true Explanation: 24 = 16 Example 3: 1 2 Input: 218 Output: false Solution: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 class Solution { public boolean isPowerOfTwo2(int n) { if (n == 0 ) { return false; } if (n == 1) { return true; } while (n % 2 == 0 && n > 2) { n = n / 2; } return n == 0 || n == 2; } public boolean isPowerOfTwo(int n) { if (n == 0 ) { return false; } if (n == Integer....

<span title='2020-06-09 00:00:00 +0000 UTC'>June 9, 2020</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;volyx

Unique Paths

A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked ‘Finish’ in the diagram below). How many possible unique paths are there? Above is a 7 x 3 grid. How many possible unique paths are there?...

<span title='2020-06-09 00:00:00 +0000 UTC'>June 9, 2020</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

Coin Change 2

You are given coins of different denominations and a total amount of money. Write a function to compute the number of combinations that make up that amount. You may assume that you have infinite number of each kind of coin. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Example 1: Input: amount = 5, coins = [1, 2, 5] Output: 4 Explanation: there are four ways to make up the amount: 5=5 5=2+2+1 5=2+1+1+1 5=1+1+1+1+1 Example 2: Input: amount = 3, coins = [2] Output: 0 Explanation: the amount of 3 cannot be made up just with coins of 2....

<span title='2020-06-08 00:00:00 +0000 UTC'>June 8, 2020</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx

Queue Reconstruction by Height

Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers (h, k), where h is the height of the person and k is the number of people in front of this person who have a height greater than or equal to h. Write an algorithm to reconstruct the queue. Note: The number of people is less than 1,100. 1 2 3 4 5 6 7 Example Input: [[7,0], [4,4], [7,1], [5,0], [6,1], [5,2]] Output: [[5,0], [7,0], [5,2], [6,1], [4,4], [7,1]] Solution:...

<span title='2020-06-07 00:00:00 +0000 UTC'>June 7, 2020</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

Top K Frequent Words

Given a non-empty list of words, return the k most frequent elements. Your answer should be sorted by frequency from highest to lowest. If two words have the same frequency, then the word with the lower alphabetical order comes first. 1 2 3 4 5 6 Example 1: Input: ["i", "love", "leetcode", "i", "love", "coding"], k = 2 Output: ["i", "love"] Explanation: "i" and "love" are the two most frequent words....

<span title='2020-06-06 00:00:00 +0000 UTC'>June 6, 2020</span>&nbsp;·&nbsp;6 min&nbsp;·&nbsp;volyx

Random Pick with Weight

Given an array w of positive integers, where w[i] describes the weight of index i, write a function pickIndex which randomly picks an index in proportion to its weight. Note: 1 <= w.length <= 10000 1 <= w[i] <= 10^5 pickIndex will be called at most 10000 times. Example 1: 1 2 3 4 Input: ["Solution","pickIndex"] [[[1]],[]] Output: [null,0] Example 2: 1 2 3 4 Input: ["Solution","pickIndex","pickIndex","pickIndex","pickIndex","pickIndex"] [[[1,3]],[],[],[],[],[]] Output: [null,0,1,1,1,0] Explanation of Input Syntax:...

<span title='2020-06-05 00:00:00 +0000 UTC'>June 5, 2020</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

Two City Scheduling

There are 2N people a company is planning to interview. The cost of flying the i-th person to city A is costs[i][0], and the cost of flying the i-th person to city B is costs[i][1]. Return the minimum cost to fly every person to a city such that exactly N people arrive in each city. Example 1: 1 2 3 4 5 6 7 8 9 Input: [[10,20],[30,200],[400,50],[30,20]] Output: 110 Explanation: The first person goes to city A for a cost of 10....

<span title='2020-06-04 00:00:00 +0000 UTC'>June 4, 2020</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx