Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions contest/src/main/java/com/github/contest/Execute.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import java.util.TreeMap
fun main() {

findAnagrams("abnkjhgidhr", "abn").also { println(it) }

}

infix fun Int.myRange(to: Int): IntRange {
Expand Down
39 changes: 39 additions & 0 deletions contest/src/main/java/com/github/contest/design/DesignLeetcode.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.github.contest.design

import java.util.LinkedList

/**
* 1352. Product of the Last K Numbers
*/
Expand Down Expand Up @@ -331,4 +333,41 @@ class RLEIterator(private val encoding: IntArray) {
return 0
}

}

/**
* 933. Number of Recent Calls
*/

class RecentCounter() {

private val queue = LinkedList<Int>()

fun ping(t: Int): Int {
queue.offer(t)

while (queue.peek() < t - 3000) queue.poll()

return queue.size
}

}

/**
* 901. Online Stock Span
*/

class StockSpanner() {

private val stocks = ArrayDeque<Pair<Int, Int>>()

fun next(price: Int): Int {
var span = 1

while (stocks.isNotEmpty() && stocks.last().first <= price) span += stocks.removeLast().second

stocks.addLast(price to span)
return span
}

}