Pattern

Implementation

A compact view of archive entries grouped by recurring technique.

172 entries

172 entries tagged as Implementation.

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

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

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