Year
2022 archive
A year-sized slice of the daily archive, ordered newest first.
62 entries
62 entries from 2022.
31.12.2022
hard980. Unique Paths III
fun uniquePathsIII(grid: Array
30.12.2022
medium797. All Paths From Source to Target
fun allPathsSourceTarget(graph: Array> {
29.12.2022
medium1834. Single-Threaded CPU
fun getOrder(tasks: Array
28.12.2022
medium1962. Remove Stones to Minimize the Total
fun minStoneSum(piles: IntArray, k: Int): Int {
27.12.2022
medium2279. Maximum Bags With Full Capacity of Rocks
fun maximumBags(capacity: IntArray, rocks: IntArray, additionalRocks: Int): Int {
26.12.2022
medium55. Jump Game
fun canJump(nums: IntArray): Boolean {
25.12.2022
easy2389. Longest Subsequence With Limited Sum
fun answerQueries(nums: IntArray, queries: IntArray): IntArray {
24.12.2022
medium790. Domino and Tromino Tiling
fun numTilings(n: Int): Int {
23.12.2022
medium309. Best Time to Buy and Sell Stock with Cooldown
data class K(val a:Int, val b: Boolean, val c:Boolean)
22.12.2022
hard834. Sum of Distances in Tree
fun sumOfDistancesInTree(n: Int, edges: Array
21.12.2022
medium886. Possible Bipartition
fun possibleBipartition(n: Int, dislikes: Array
20.12.2022
medium841. Keys and Rooms
fun canVisitAllRooms(rooms: List>): Boolean {
19.12.2022
easy1971. Find if Path Exists in Graph
fun validPath(n: Int, edges: Array
18.12.2022
medium739. Daily Temperatures
fun dailyTemperatures(temperatures: IntArray): IntArray {
17.12.2022
medium150. Evaluate Reverse Polish Notation
fun evalRPN(tokens: Array
16.12.2022
easy232. Implement Queue using Stacks
class MyQueue() {
15.12.2022
medium1143. Longest Common Subsequence
fun longestCommonSubsequence(text1: String, text2: String): Int {
14.12.2022
medium198. House Robber
fun rob(nums: IntArray): Int {
13.12.2022
medium931. Minimum Falling Path Sum
fun minFallingPathSum(matrix: Array
12.12.2022
easy70. Climbing Stairs
val cache = mutableMapOf
11.12.2022
hard124. Binary Tree Maximum Path Sum
fun maxPathSum(root: TreeNode?): Int {
10.12.2022
medium1339. Maximum Product of Splitted Binary Tree
fun maxProduct(root: TreeNode?): Int {
9.12.2022
medium1026. Maximum Difference Between Node and Ancestor
fun maxAncestorDiff(root: TreeNode?): Int {
8.12.2022
easy872. Leaf-Similar Trees
fun leafSimilar(root1: TreeNode?, root2: TreeNode?): Boolean {
7.12.2022
easy938. Range Sum of BST
fun rangeSumBST(root: TreeNode?, low: Int, high: Int): Int =
6.12.2022
medium328. Odd Even Linked List
// 1 2
5.12.2022
easy876. Middle of the Linked List
fun middleNode(head: ListNode?, fast: ListNode? = head): ListNode? =
4.12.2022
medium2256. Minimum Average Difference
fun minimumAverageDifference(nums: IntArray): Int {
3.12.2022
medium451. Sort Characters By Frequency
fun frequencySort(s: String): String =
2.12.2022
mediumDetermine If Two Strings Are Close
// cabbba -> c aa bbb -> 1 2 3
1.12.2022
easy1704. Determine if String Halves Are Alike
fun halvesAreAlike(s: String): Boolean {
30.11.2022
easy1207. Unique Number of Occurrences
fun uniqueOccurrences(arr: IntArray): Boolean {
29.11.2022
medium380. Insert Delete GetRandom O(1)
class RandomizedSet() {
28.11.2022
medium2225. Find Players With Zero or One Losses
fun findWinners(matches: Array> {
27.11.2022
hard446. Arithmetic Slices II - Subsequence
fun numberOfArithmeticSlices(nums: IntArray): Int {
26.11.2022
hard1235. Maximum Profit in Job Scheduling
fun jobScheduling(startTime: IntArray, endTime: IntArray, profit: IntArray): Int {
25.11.2022
medium907. Sum of Subarray Minimums
data class V(val v: Int, val count: Int)
24.11.2022
medium79. Word Search
fun exist(board: Array
23.11.2022
mediumValid Sudoku
fun isValidSudoku(board: Array
22.11.2022
mediumPerfect Squares
val cache = mutableMapOf
21.11.2022
mediumNearest Exit From Entrance In Maze
fun nearestExit(maze: Array
20.11.2022
hardBasic Calculator
fun calculate(s: String): Int {
19.11.2022
hardErect The Fence
fun outerTrees(trees: Array
18.11.2022
easyUgly Number
fun isUgly(n: Int): Boolean {
17.11.2022
mediumRectangle Area
class Solution {
16.11.2022
easyGuess Number Higher Or Lower
override fun guessNumber(n:Int):Int {
15.11.2022
mediumCount Complete Tree Nodes
x
14.11.2022
mediumMost Stones Removed With Same Row Or Column
From observing the problem, we can see, that the task is in fact is to find an isolated islands
13.11.2022
mediumReverse Words In A String
A simple trick: reverse all the string, then reverse each word.
12.11.2022
hardFind Median From Data Stream
To find the median we can maintain two heaps: smaller and larger. One decreasing and one increasing.
11.11.2022
easyRemove Duplicates From Sorted Array
Just do what is asked. Keep track of the pointer to the end of the "good" part.
10.11.2022
easyRemove All Adjacent Duplicates In String
Just scan symbols one by one and remove duplicates from the end.
9.11.2022
mediumOnline Stock Span
So, we need to keep increasing sequence of numbers, increasing/decreasing stack will help.
8.11.2022
easyMake The String Great
The simplest solution is just to simulate all the process, as input string is just 100 symbols.
7.11.2022
easyMaximum 69 Number
The simplest implementations would be converting to array of digits, replacing the first and converting back.
6.11.2022
hardOrderly Queue
One idea that come to my mind is: if k >= 2 then you basically can swap any adjacent elements. That means you can actually sort all the characters.
6.11.2022
hardWord Search Ii
Use trie + dfs
4.11.2022
easyReverse Vowels Of A String
Straightforward solution : use two pointers method and scan from the both sides.
3.11.2022
mediumLongest Palindrome By Concatenating Two Letter Words
This is a counting task, can be solved linearly.
2.11.2022
mediumMinimum Genetic Mutation
make graph
1.11.2022
mediumWhere Will The Ball Fall
This is a geometry problem, but seeing the pattern might help. We can spot that each row is an action sequence: -1 -1 -1 shifts balls left, and 1 1 1 shifts balls to the right. Corners can be formed only with -1 1 sequence.
31.10.2022
easyToeplitz Matrix
just compare adjacent rows, they must have an equal elements except first and last