Elastic Coding Interview Questions
25 Elastic coding interview problems with full optimal solutions — 8 easy, 12 medium, 5 hard. Every problem ships with multiple approaches (brute-force first, then the optimal), complexity tables for each, company-specific tips on what an Elastic interviewer values, and a FAQ section.
- #1easyvery frequently asked
1. Two Sum
Find two indices in an array whose values sum to a target. At Elastic, this tests your instinct for trading memory for speed — the same hash-map lookup pattern powers fast term lookups inside Elasticsearch's inverted index.
- #3mediumvery frequently asked
3. Longest Substring Without Repeating Characters
Find the length of the longest substring with all unique characters. Elastic favors this problem because the sliding-window technique it demands is the same mental model used in Elasticsearch's windowed token analysis during text tokenization and shingle generation.
- #4hardsometimes asked
4. Median of Two Sorted Arrays
Find the median of two sorted arrays in O(log(m+n)) time. Elastic includes this hard problem because computing global percentiles across distributed shards — a core Elasticsearch aggregation feature — requires exactly this kind of partitioned-binary-search reasoning over sorted shard segments.
- #15mediumfrequently asked
15. 3Sum
Find all unique triplets in an array that sum to zero. Elastic uses this to assess whether candidates can combine sorting and two-pointer techniques without double-counting — the same deduplication challenge that arises when Elasticsearch merges results from replicated shards.
- #20easyfrequently asked
20. Valid Parentheses
Determine whether a string of brackets is balanced. Elastic reaches for this in phone screens because the stack-based parse pattern is directly analogous to query-string and JSON document validation that Elasticsearch performs on every indexed document.
- #21easyfrequently asked
21. Merge Two Sorted Lists
Merge two sorted linked lists into one sorted list. Elastic interviews this because it is the atomic merge step in merge sort — and merge sort is the exact mechanism Elasticsearch uses when combining sorted posting lists during multi-term query execution.
- #23hardvery frequently asked
23. Merge K Sorted Lists
Merge K sorted linked lists into one sorted list. This is one of the most Elastic-relevant hard problems in existence — merging sorted posting lists from K shards is the exact operation Elasticsearch performs on every multi-shard search query, and the min-heap approach maps one-to-one to the coordinating node's result collection logic.
- #42hardfrequently asked
42. Trapping Rain Water
Compute how much water is trapped between elevation bars after rain. Elastic uses this problem as a hard two-pointer question that tests the ability to reason about running maximums from both directions — the same prefix/suffix scan pattern underlies Elasticsearch's range-scoring and gap-detection in time-series anomaly detection.
- #49mediumfrequently asked
49. Group Anagrams
Group a list of strings so that anagrams appear together. This is a canonical Elastic question — the sorted-string or frequency-vector canonical key pattern is exactly the normalization step Elasticsearch's token filters apply before building the inverted index.
- #53easyfrequently asked
53. Maximum Subarray
Find the contiguous subarray with the largest sum. Elastic reaches for Kadane's algorithm because it illustrates how a single-pass decision — keep accumulating or restart — is the same greedy insight driving Elasticsearch's segment-level scoring and relevance windowing.
- #56mediumfrequently asked
56. Merge Intervals
Merge all overlapping intervals into a minimal non-overlapping set. Elastic frequently asks this because merging time-range queries, log time spans, and APM trace windows are everyday operations in Elasticsearch and Kibana — getting the overlap condition exactly right under edge cases is a real engineering concern.
- #70easysometimes asked
70. Climbing Stairs
Count the distinct ways to climb n stairs taking 1 or 2 steps at a time. Elastic uses this as an entry-level dynamic programming probe — if you can articulate why the recurrence is Fibonacci and spot the O(1) space optimization, you signal that you think about caching and state compression the way Elasticsearch's query cache does.
- #121easyfrequently asked
121. Best Time to Buy and Sell Stock
Find the maximum profit from a single buy-low-sell-high transaction. Elastic uses this pattern to test sliding-window and running-minimum thinking — the same mental model used when computing rolling aggregations over time-series log data in Elasticsearch.
- #127hardsometimes asked
127. Word Ladder
Find the shortest transformation sequence from one word to another, changing one letter at a time. Elastic uses this BFS-on-a-word-graph problem because edit-distance graph traversal and fuzzy query shortest paths underpin Elasticsearch's fuzziness and Levenshtein automaton query routing.
- #139mediumfrequently asked
139. Word Break
Determine if a string can be segmented into words from a dictionary. Elastic interviews this because token segmentation is at the core of Elasticsearch's text analysis pipeline — understanding which substrings can be valid tokens is exactly what analyzers compute before indexing.
- #141easysometimes asked
141. Linked List Cycle
Detect whether a linked list contains a cycle. Elastic uses Floyd's tortoise-and-hare algorithm here as a proxy for distributed-systems intuition — detecting liveness vs. livelock in a cluster follows the same principle of needing two probes at different rates to distinguish 'still making progress' from 'spinning in a loop'.
- #146mediumvery frequently asked
146. LRU Cache
Design a cache that evicts the least-recently-used item when full. Elastic asks this because LRU is a first-class concern in search infrastructure — Elasticsearch's request cache and field data cache both use LRU eviction, and candidates who can implement it from scratch demonstrate exactly the systems intuition Elastic values.
- #200mediumfrequently asked
200. Number of Islands
Count connected components of '1' cells in a 2D grid. Elastic reaches for this problem because BFS/DFS on a grid is a direct analogue of cluster connectivity analysis — the same reasoning applies when determining which Elasticsearch nodes belong to the same cluster partition after a network split.
- #206easyfrequently asked
206. Reverse Linked List
Reverse a singly-linked list in place. Elastic uses pointer-manipulation questions like this to verify that candidates can reason about mutable state without a garbage-collection safety net — critical intuition for writing correct segment merging and linked-structure traversal in distributed search engines.
- #207mediumfrequently asked
207. Course Schedule
Determine if you can finish all courses given prerequisite dependencies — essentially cycle detection in a directed graph. Elastic interviews this because topological ordering and DAG validation are fundamental to Elasticsearch's pipeline processor chains and ingest node dependency resolution.
- #208mediumvery frequently asked
208. Implement Trie (Prefix Tree)
Build a prefix tree supporting insert, search, and startsWith. Tries are the foundational data structure behind Elasticsearch's prefix query, completion suggester, and edge-n-gram token filter — implementing one from scratch is one of the most domain-relevant questions Elastic asks.
- #238mediumfrequently asked
238. Product of Array Except Self
Return an array where each element is the product of all other elements, without using division. Elastic uses this to test prefix/suffix scan thinking — the same cumulative-scan pattern drives Elasticsearch's pipeline aggregations that compute running totals across document sets.
- #347mediumvery frequently asked
347. Top K Frequent Elements
Return the k most frequent elements in an array. Elastic asks this because computing top-K term frequencies is at the heart of Elasticsearch's terms aggregation and relevance scoring — and bucket-sort vs. heap trade-offs map directly to how Elasticsearch chooses between different aggregation strategies.
- #642hardfrequently asked
642. Design Search Autocomplete System
Design a system that returns top-3 historical search suggestions as you type. This is arguably the most Elastic-aligned hard coding question: Elasticsearch's completion suggester is a production implementation of exactly this design, combining a Trie with frequency-ranked retrieval — candidates who know both the data structure and the ranking heuristic stand out immediately.
- #658mediumsometimes asked
658. Find K Closest Elements
Return the k integers in a sorted array closest to a target value. Elastic asks this because nearest-neighbor lookup in a sorted index is the core of Elasticsearch's range queries and numeric field approximations — binary search to anchor + window expansion is a real optimization pattern in search engines.