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 in Java: Time and Space Complexity for Coding Interviews
Big O notation describes how the running time or the memory of an algorithm grows when its input grows. An algorithm that is fast for 100 users can be unusable...
Depth-First Search (DFS) in Java: Graph Traversal Explained, with BFS
Depth-first search (DFS) is an algorithm for visiting every node of a graph. It starts at one node and follows one path as deep as it can before it backs...
Binary Search Tree in Java: Insert, Search, Delete and Traversal (with GTIN Example)
A binary search tree (BST) keeps its data sorted while still letting you insert and delete quickly. A sorted array finds an item fast with binary search, but inserting means...
Knapsack Problem in Java: Fill a Shopping Basket on a Budget (Greedy vs Dynamic Programming)
You have a fixed budget and a list of products, each with a price and something you want as much of as possible. Which products should you buy? This is...
Smallest Number with the Same Number of Digits in Java (Coding Interview Problem)
The problem: write a method that, given an integer N, returns the smallest number with the same number of digits.