File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed
contest/src/main/java/com/github/contest Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import java.util.TreeMap
1717fun main () {
1818
1919 findAnagrams(" abnkjhgidhr" , " abn" ).also { println (it) }
20+
2021}
2122
2223infix fun Int.myRange (to : Int ): IntRange {
Original file line number Diff line number Diff line change 11package com.github.contest.design
22
3+ import java.util.LinkedList
4+
35/* *
46 * 1352. Product of the Last K Numbers
57 */
@@ -331,4 +333,41 @@ class RLEIterator(private val encoding: IntArray) {
331333 return 0
332334 }
333335
336+ }
337+
338+ /* *
339+ * 933. Number of Recent Calls
340+ */
341+
342+ class RecentCounter () {
343+
344+ private val queue = LinkedList <Int >()
345+
346+ fun ping (t : Int ): Int {
347+ queue.offer(t)
348+
349+ while (queue.peek() < t - 3000 ) queue.poll()
350+
351+ return queue.size
352+ }
353+
354+ }
355+
356+ /* *
357+ * 901. Online Stock Span
358+ */
359+
360+ class StockSpanner () {
361+
362+ private val stocks = ArrayDeque <Pair <Int , Int >>()
363+
364+ fun next (price : Int ): Int {
365+ var span = 1
366+
367+ while (stocks.isNotEmpty() && stocks.last().first <= price) span + = stocks.removeLast().second
368+
369+ stocks.addLast(price to span)
370+ return span
371+ }
372+
334373}
You can’t perform that action at this time.
0 commit comments