Posts in category 'algorithms'

Items in Containers: Count Items in Closed Compartments (Code Interview Problem)

This one shows up in online coding assessments under the name Items in Containers, and it’s a trap: the obvious solution passes the examples and then times out on the...

Shopping Options: Count the Ways to Buy Within a Budget (Code Interview Problem)

Four nested loops solve this problem in five minutes, and that’s exactly the trap. With up to 1,000 prices per category, brute force has to check 10¹² combinations. Here’s how...

Random Without Repeats in Java: Schedule Posts to X with Spring Boot and a Shuffle Bag

You’ve written a hundred articles, and you want a bot to share one of them every three hours, even while you sleep. “Pick a random article” sounds like one line...

Assemble Parts in Minimum Time: Greedy Min-Heap Solution in Java (Code Interview Problem)

This problem looks easy, and most candidates find the right idea within minutes. Then many of them implement it in a way that passes the examples and fails on half...

Merge Two Sorted Lists in Java: Array List and Linked List Solutions

Merging two sorted lists is one of the classic coding interview problems, and one of the most useful: it is the heart of merge sort, of merging k sorted lists,...

Big O Notation and Analysis of Algorithms - coding interview

Big O Notation is a mathematical notation that helps us analyze how complex an algorithm is in terms of time and space. When we build an application for one user...

Graphs: Depth-First Search

Depth-First Search (DFS), is an algorithm to search for information in Graphs.

Tree data structure: Binary Search Tree

Tree data structures are non-linear data structures, and they allow us to implement algorithms much faster than when using linear data structures.

Given N, find the smallest number with the same digits

Write a method that, given an original number N, returns the smallest number with the same number of digits.