Language

Kotlin archive

Every library entry that currently exposes Kotlin code or a Kotlin solution link.

1281 entries

Daily solutions with Kotlin available either directly in the archive or via linked solution pages.

04.01.2025

medium

1930. Unique Length-3 Palindromic Subsequences

Count palindromes of length 3

building a HashSet can be slower then just checking for contains 26 times using unordered_set to count unique characters in the substring finding the span between first and last occurrences of a character counting unique characters within the substring defined by character occurrences manipulating and analyzing string content implicit use of string as an array of characters

27.08.2024

medium

1514. Path with Maximum Probability

Max path in a weighted graph

g queue shortest path calculation via probability multiplication using a priority queue (implicitly via BFS/queue structure) to find paths with maximum probability, updating probabilities based on multiplicative factors. building an adjacency list representation for the graph where edges store transition probabilities. weighted directed/undirected graph with probability weights

14.10.2023

hard

2742. Painting the Walls

Min cost to complete all tasks using one paid cost[] & time[] and one free 0 & 1 workers

dp_memo depth-first-search memoization_with_state_compression bit-shifting_for_state_storage scheduling_and_cost_minimization implicit_state_space

25.05.2023

medium

837. New 21 Game

Probability sum of random numbers 1..maxPts sum be < n after it overflow k.

cache depth-first-search memoization_with_recurrence algebraic_manipulation boundary_condition_analysis probability

10.05.2023

medium

59. Spiral Matrix II

to detect an empty cell, we can check it for == 0

Array is used to represent the matrix and store results. Iterative traversal of the matrix is used to fill the spiral pattern. Simulating a robot moving in a spiral pattern to fill the matrix. Checking boundaries and visited status before moving to the next cell. The problem involves generating a spiral matrix. Using 2D arrays to represent the matrix.

29.01.2023

hard

460. LFU Cache

one thing to note, on each increaseFreq operation we are retrieving a random item from TreeMap, that increases time to O(log(F)), where F is a unique set of frequencies.

TreeMap LinkedHashSet Frequency Bucketing Ordered Access Lists Cache Data Structures

8.11.2022

easy

Make The String Great

The simplest solution is just to simulate all the process, as input string is just 100 symbols.

char array (toCharArray) string manipulation nested loops for pairwise comparison iterative process to resolve conflicts checking adjacent/non-adjacent characters for equality and difference string processing

1.11.2022

medium

Where 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.

indToBall iterative_update tracking_ball_positions identifying_shift_rules grid_manipulation