The most asked Crystal interview questions with structured answers — a quick answer, a clear explanation and working code for each. Covers basics for freshers through advanced, scenario and coding questions for experienced developers.
Updated November 2026 Reviewed by Abhishek Kumar 119 min read
99 Crystal interview questions, grouped by level: freshers, intermediate, experienced and coding.
Every answer starts with a one-line “Quick answer” you can say out loud, followed by the explanation and runnable code.
Use the filter bar to practise only the level you are interviewing for, then test yourself with the free Crystal quiz.
What is Crystal, and why do interviewers ask about it?
This page provides a comprehensive collection of Crystal Interview Questions and Answers to help students, software engineers, and experienced developers prepare for technical interviews. The questions range from beginner fundamentals to advanced Crystal programming concepts with practical examples.
Crystal is a modern compiled programming language inspired by Ruby, designed to provide Ruby-like syntax with the performance of statically typed compiled languages. It features powerful type inference, native compilation, concurrency with fibers, macros, and excellent runtime performance.
These interview questions cover Crystal language fundamentals, variables, methods, classes, modules, macros, fibers, channels, collections, exception handling, memory management, and performance optimization to help you succeed in Crystal developer interviews.
Why companies hire for Crystal
Ruby-like syntax – expressive and developer-friendly with minimal boilerplate
Blazing fast performance – compiled to native code with efficient memory usage
Powerful type inference – static typing without explicit annotations
Built-in concurrency – lightweight fibers and channels for concurrent programming
Metaprogramming – powerful macros for code generation and DSLs
Interoperability – C bindings and seamless integration with C libraries
Growing ecosystem – active community with development frameworks like Kemal
99 shown
Basic Crystal Interview Questions for Freshers
5 questions
Start here if you are a fresher or switching to Crystal. These fundamentals are asked in almost every first-round and campus interview.
Quick answerCrystal is a statically typed, compiled programming language with Ruby-like syntax. It combines the performance of C with the productivity of Ruby.
Ruby-like Syntax: Clean and readable code
Static Typing: Type inference and compile-time checks
Performance: Compiled to native code
Concurrency: Fibers and channels for lightweight concurrency
Quick answerA class encapsulates data and behavior. Crystal uses properties ( getter, setter) for clean access control and constructors for initialization.
A class encapsulates data and behavior. Crystal uses properties (getter, setter) for clean access control and constructors for initialization.
Quick answerConstructors are defined using the initialize method. Crystal supports multiple constructors via method overloading. Finalizers ( finalize) are called by the garbage collector.
Constructors are defined using the initialize method. Crystal supports multiple constructors via method overloading. Finalizers (finalize) are called by the garbage collector.
Quick answerAn Array is a dynamic collection with O(1) random access. Crystal arrays are typed and integrate with the standard library's functional methods.
Quick answerHash is a key-value store with O(1) average operations. Set stores unique elements with O(1) lookups. Both are part of the standard library.
Quick answerRecursion in Crystal works the same as other languages — a function calling itself. Crystal supports tail recursion optimization in some cases.
Always define a base case
Each call creates a new stack frame
Tail recursion can be optimized
Use yield for lazy recursion
Crystal
# Recursion in Crystaldeffactorial(n : Int32) : Int32
return1if n <= 1
n * factorial(n - 1)
enddeffibonacci(n : Int32) : Int32
return n if n <= 1
fibonacci(n - 1) + fibonacci(n - 2)
enddefhanoi(n : Int32, from : Char, to : Char, aux : Char)
if n == 1
puts "Move disk 1: #{from} -> #{to}"returnend
hanoi(n - 1, from, aux, to)
puts "Move disk #{n}: #{from} -> #{to}"
hanoi(n - 1, aux, to, from)
enddefpower(base : Int32, exp : Int32) : Int32
return1if exp == 0if exp.even?
half = power(base, exp // 2)
half * half
else
base * power(base, exp - 1)
endend
puts "5! = #{factorial(5)}"
puts "fib(8) = #{fibonacci(8)}"
puts "2^10 = #{power(2, 10)}"
puts "Tower of Hanoi (3 disks):"
hanoi(3, 'A', 'C', 'B')
Quick answerModules organize code and provide namespaces. They can contain methods, constants, and other modules for logical grouping.
module Name — define module
include Module — include module methods
require — load external files
Nested modules with :: syntax
Crystal
# Modules and NamespacesmoduleMathUtils
PI = 3.14159265358979moduleGeometrydefself.circle_area(r : Float64)
PI * r * r
enddefself.rect_area(w : Float64, h : Float64)
w * h
endendmoduleAdvancedmoduleAlgebradefself.power(base : Float64, exp : Int32)
result = 1.0
exp.times { result *= base }
result
endendendendmodulePhysics
G = 9.81moduleMechanicsdefself.kinetic_energy(m : Float64, v : Float64)
0.5 * m * v * v
enddefself.weight(mass : Float64)
mass * G
endendendincludeMathUtils::Geometry
includeMathUtils::Advanced::Algebra
puts "PI = #{MathUtils::PI}"
puts "Circle area = #{circle_area(5.0)}"
puts "2^8 = #{power(2.0, 8)}"
puts "Weight(70kg) = #{Physics::Mechanics.weight(70)} N"# Using alias
Math = MathUtils::Geometry
puts "Rect area = #{Math.rect_area(4, 5)}"
Quick answerThe Two Sum problem uses a Hash for O(n) lookup. For each element, check if the complement exists in the hash for optimal performance.
Hash approach: O(n) time, O(n) space
Two pointer (sorted): O(n log n) time
Tuples for clean pair returns
Common coding interview question
Crystal
# Two Sum Problem in Crystal# Hash map approach O(n)deftwo_sum(nums : Array(Int32), target : Int32)
map = {} of Int32 => Int32
nums.each_with_index do |num, i|
complement = target - num
return {map[complement], i} if map.has_key?(complement)
map[num] = i
endnilend# Two pointer (sorted input)deftwo_sum_pairs(arr : Array(Int32), target : Int32)
result = [] of Tuple(Int32, Int32)
l = 0
r = arr.size - 1while l < r
sum = arr[l] + arr[r]
if sum == target
result << {arr[l], arr[r]}
l += 1
r -= 1elsif sum < target
l += 1else
r -= 1endend
result
end
nums = [2, 7, 11, 15]
res = two_sum(nums, 9)
puts "Indices: [#{res[0]}, #{res[1]}]"
sorted = [1, 2, 3, 4, 6]
two_sum_pairs(sorted, 6).each do |a, b|
puts "Pair: #{a} + #{b}"end
Quick answerA two-pass left/right product approach achieves O(n) time and O(1) extra space. Array.new initializes the result array.
Left pass: prefix products into result
Right pass: multiply suffix product
Time O(n), Space O(1) extra
No division needed — handles zeros
Crystal
# Product of Array Except Self in Crystaldefproduct_except_self(nums : Array(Int32))
n = nums.size
result = Array.new(n, 1)
# Left pass
(1...n).each do |i|
result[i] = result[i - 1] * nums[i - 1]
end# Right pass
right = 1
(n - 1).downto(0).each do |i|
result[i] *= right
right *= nums[i]
end
result
end
nums = [1, 2, 3, 4]
res = product_except_self(nums)
puts "Output: #{res.join(" ")}"
Quick answerSpiral Matrix Traversal uses four shrinking boundary pointers: top, bottom, left, right. Each pass around the boundary adds elements.
Traverse: right → down → left → up
Shrink boundaries after each direction
Check boundaries before left/up traversal
Time O(m*n), Space O(1) excluding result
Crystal
# Spiral Matrix in Crystaldefspiral_order(matrix)
result = [] of Int32
top = 0
bottom = matrix.size - 1
left = 0
right = matrix[0].size - 1while top <= bottom && left <= right
(left..right).each { |i| result << matrix[top][i] }
top += 1
(top..bottom).each { |i| result << matrix[i][right] }
right -= 1if top <= bottom
(right).downto(left).each { |i| result << matrix[bottom][i] }
bottom -= 1endif left <= right
(bottom).downto(top).each { |i| result << matrix[i][left] }
left += 1endend
result
end
mat = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16]
]
puts "Spiral: #{spiral_order(mat).join(" ")}"
How interviewers ask it“Coding-round task — implement Shell Sort and Interpolation Search in Crystal. Explain your approach before you write the code.”
Quick answerCrystal uses Fibers and Channels for concurrency. spawn creates a fiber and Channel enables communication between fibers.
spawn — creates a new fiber
Channel(T) — communication between fibers
send — sends value to channel
receive — receives value from channel
Crystal
# Async/Await and Fibersrequire"fiber"deffetch_data(url : String, delay : Int32)
Fiber.yield"Data from #{url}"enddefcompute(a : Int32, b : Int32)
Fiber.yield
a + b
end# Basic async
fiber1 = Fiber.new do
result = fetch_data("api.example.com", 500)
puts result
end
fiber1.resume
# Parallel async tasks
fibers = [] of Fiber
["source1", "source2", "source3"].each do |url|
fibers << Fiber.new { puts fetch_data(url, 200) }
end
fibers.each { |f| f.resume }
# Channel for communication
channel = Channel(String).new
spawn do
channel.send "Data from channel"end
puts channel.receive
# Parallel processing with channels
numbers = (1..10).to_a
results = [] of Int32
numbers.each do |n|
spawn do
Fiber.yield
results << n * n
endend
Fiber.yield
puts "Squares: #{results.join(", ")}"
Quick answerCrystal supports multiple inheritance through modules. A class can include multiple modules, combining capabilities from different sources.
Include multiple modules with include
Module methods can be overridden
Modules can define abstract methods
Used for mixins and capability composition
Crystal
# Multiple Inheritance via ModulesmoduleVehicle
property speed : Int32
abstractdefmoveendmoduleElectric
property battery : Int32
abstractdefchargeendclassElectricCarinclude Vehicle
include Electric
property model : String
definitialize(@model : String, @speed : Int32, @battery : Int32)
enddefdisplay
puts "Model: #{@model}"
puts "Speed: #{@speed} km/h"
puts "Battery: #{@battery}%"enddefmove
puts "#{@model} glides silently at #{@speed} km/h"enddefcharge
puts "Charging battery: #{@battery}%"endend
tesla = ElectricCar.new("Tesla Model 3", 250, 85)
tesla.display
tesla.move
tesla.charge
Quick answerCrystal provides PriorityQueue in the standard library. For K Largest Elements, use a min-heap of size k. Merge K Sorted Arrays uses a priority queue.
PriorityQueue(T, U) — O(log n) operations
K Largest: min-heap of size k
Merge K sorted: tuple with value, array index, element index
Custom comparators for priority
Crystal
# Heap and Priority Queue in Crystal# K largest elementsdefk_largest(arr : Array(Int32), k : Int32)
min_heap = [] of Int32
arr.each do |x|
min_heap << x
min_heap.sort!
if min_heap.size > k
min_heap.shift
endend
min_heap
end# Merge K sorted arraysdefmerge_k_sorted(arrays : Array(Array(Int32)))
pq = PriorityQueue(Tuple(Int32, Int32, Int32), Int32).new
arrays.each_with_index do |arr, i|
pq.push({arr[0], i, 0}, arr[0]) if arr.size > 0end
result = [] of Int32
while !pq.empty?
val, i, j = pq.pop
result << val
if j + 1 < arrays[i].size
next_val = arrays[i][j + 1]
pq.push({next_val, i, j + 1}, next_val)
endend
result
end
arr = [3, 1, 5, 12, 2, 11, 9]
top3 = k_largest(arr, 3)
puts "Top 3: #{top3.join(" ")}"
k_arr = [
[1, 4, 7],
[2, 5, 8],
[3, 6, 9]
]
merged = merge_k_sorted(k_arr)
puts "Merged: #{merged.join(" ")}"
Quick answerThe Sliding Window Maximum uses a Deque as a monotonic queue. It stores indices in decreasing order of value.
Deque as monotonic queue
Remove out-of-window indices from front
Remove smaller elements from rear
Front always has the current window maximum
Crystal
# Sliding Window Maximum in Crystaldefmax_sliding_window(nums : Array(Int32), k : Int32)
dq = Deque(Int32).new
result = [] of Int32
nums.each_with_index do |num, i|
# Remove out-of-window indiceswhile !dq.empty? && dq.first < i - k + 1
dq.shift
end# Remove smaller elements from rearwhile !dq.empty? && nums[dq.last] < nums[i]
dq.pop
end
dq.push(i)
if i >= k - 1
result << nums[dq.first]
endend
result
end
nums = [1, 3, -1, -3, 5, 3, 6, 7]
k = 3
res = max_sliding_window(nums, k)
puts "Sliding window max: #{res.join(" ")}"
Quick answerThe KMP Algorithm uses an LPS array to skip unnecessary comparisons, achieving O(n+m) time complexity.
LPS array computed in O(m)
Never moves backward in the text
Returns all match positions
Time O(n+m), Space O(m)
Crystal
# KMP String Matching in Crystaldefbuild_lps(pattern : String)
m = pattern.size
lps = Array.new(m, 0)
len = 0
i = 1while i < m
if pattern[i] == pattern[len]
len += 1
lps[i] = len
i += 1elsif len > 0
len = lps[len - 1]
else
lps[i] = 0
i += 1endend
lps
enddefkmp_search(text : String, pattern : String)
positions = [] of Int32
lps = build_lps(pattern)
n = text.size
m = pattern.size
i = 0
j = 0while i < n
if text[i] == pattern[j]
i += 1
j += 1endif j == m
positions << i - j
j = lps[j - 1]
elsif i < n && text[i] != pattern[j]
if j > 0
j = lps[j - 1]
else
i += 1endendend
positions
end
text = "AABAACAADAABAABA"
pat = "AABA"
pos = kmp_search(text, pat)
puts "Pattern found at: #{pos.join(" ")}"
Quick answerBit manipulation in Crystal uses the same operators as C. XOR for finding unique elements and Brian Kernighan's algorithm for bit counting.
Operators: &, |, ^, ~, <<, >>
XOR trick: a ^ a = 0, a ^ 0 = a
Brian Kernighan: n &= n - 1
Power of 2 check: (n & (n - 1)) == 0
Crystal
# Bit Manipulation in Crystaldefis_bit_set(n : Int32, p : Int32) : Bool
(n >> p) & 1 == 1enddefset_bit(n : Int32, p : Int32) : Int32
n | (1 << p)
enddefclear_bit(n : Int32, p : Int32) : Int32
n & ~(1 << p)
enddeftoggle_bit(n : Int32, p : Int32) : Int32
n ^ (1 << p)
enddefcount_bits(n : Int32) : Int32
count = 0while n > 0
n &= n - 1
count += 1end
count
enddefis_power_of_2(n : Int32) : Bool
n > 0 && (n & (n - 1)) == 0enddeffind_unique(arr : Array(Int32)) : Int32
result = 0
arr.each { |x| result ^= x }
result
end
n = 0b10110100
puts "Number: #{n}"
puts "Bit 2 set? #{is_bit_set(n, 2)}"
puts "Set bit 0: #{set_bit(n, 0)}"
puts "Clear bit 4: #{clear_bit(n, 4)}"
puts "Toggle bit 7: #{toggle_bit(n, 7)}"
puts "Count bits: #{count_bits(n)}"
puts "isPow2(16): #{is_power_of_2(16)}"
arr = [2, 3, 5, 4, 5, 3, 4]
puts "Unique: #{find_unique(arr)}"
Quick answerNumber Theory includes algorithms for GCD, LCM, prime numbers, sieve, and modular exponentiation.
GCD/LCM: Euclidean algorithm
Prime Detection: Trial division, sieve
Sieve of Eratosthenes: O(n log log n)
Modular exponentiation: O(log n)
exp >>= 1 for fast division
Crystal
# Number Theory in Crystaldefgcd(a : Int32, b : Int32) : Int32
b == 0 ? a : gcd(b, a % b)
enddeflcm(a : Int32, b : Int32) : Int32
a // gcd(a, b) * b
enddefis_prime(n : Int32) : Bool
returnfalseif n < 2
(2..Math.sqrt(n).to_i).each do |i|
returnfalseif n % i == 0endtrueenddefsieve(limit : Int32)
not_prime = Array.new(limit + 1, false)
not_prime[0] = trueif limit >= 0
not_prime[1] = trueif limit >= 1
(2..Math.sqrt(limit).to_i).each do |i|
nextif not_prime[i]
(i * i..limit).step(i).each do |j|
not_prime[j] = trueendend
(2..limit).select { |i| !not_prime[i] }
enddefmod_pow(base : Int64, exp : Int64, mod : Int64) : Int64
result = 1_i64
base %= mod
while exp > 0
result = (result * base) % mod if exp.odd?
base = (base * base) % mod
exp >>= 1end
result
end
puts "GCD(48,18)=#{gcd(48, 18)}"
puts "LCM(4,6)=#{lcm(4, 6)}"
puts "isPrime(17)=#{is_prime(17)}"
primes = sieve(50)
puts "Primes: #{primes.join(" ")}"
puts "2^10 mod 1000 = #{mod_pow(2, 10, 1000)}"
Quick answerThe two pointers technique uses two index variables moving towards each other to solve array problems in O(n) time.
Container with most water: maximize area between bars
3-Sum: fix one element, two-pointer the rest
Skip duplicates for unique triplets
Requires sorted input for most applications
Crystal
# Two Pointers Technique in Crystal# Container with most waterdefmax_water(height : Array(Int32))
l = 0
r = height.size - 1
max_area = 0while l < r
area = Math.min(height[l], height[r]) * (r - l)
max_area = Math.max(max_area, area)
if height[l] < height[r]
l += 1else
r -= 1endend
max_area
end# 3-sumdefthree_sum(nums : Array(Int32))
nums.sort!
result = [] of Array(Int32)
(0...nums.size - 2).each do |i|
nextif i > 0 && nums[i] == nums[i - 1]
l = i + 1
r = nums.size - 1while l < r
sum = nums[i] + nums[l] + nums[r]
if sum == 0
result << [nums[i], nums[l], nums[r]]
l += 1while l < r && nums[l] == nums[l + 1]
r -= 1while l < r && nums[r] == nums[r - 1]
l += 1
r -= 1elsif sum < 0
l += 1else
r -= 1endendend
result
end
h = [1, 8, 6, 2, 5, 4, 8, 3, 7]
puts "Max water: #{max_water(h)}"
nums = [-1, 0, 1, 2, -1, -4]
three_sum(nums).each { |triplet| puts triplet.join(" ") }
Quick answerCrystal arrays make DP table initialization and traversal clean. Coin Change (min coins), Count Ways, and Subset Sum are solved with bottom-up DP.
Coin Change: Math.min for optimization
Count Ways: unbounded knapsack variant
Subset Sum: 0/1 knapsack with bool table
All O(n * amount) time
Crystal
# Coin Change and Subset Sum in Crystal# Minimum coinsdefcoin_change(coins : Array(Int32), amount : Int32)
dp = Array.new(amount + 1, Int32::MAX)
dp[0] = 0
(1..amount).each do |i|
coins.each do |c|
if c <= i && dp[i - c] != Int32::MAX
dp[i] = Math.min(dp[i], dp[i - c] + 1)
endendend
dp[amount] == Int32::MAX ? -1 : dp[amount]
end# Count waysdefcount_ways(coins : Array(Int32), amount : Int32)
dp = Array.new(amount + 1, 0)
dp[0] = 1
coins.each do |c|
(c..amount).each do |i|
dp[i] += dp[i - c]
endend
dp[amount]
end# Subset sumdefsubset_sum(arr : Array(Int32), target : Int32)
n = arr.size
dp = Array.new(n + 1) { Array.new(target + 1, false) }
(0..n).each { |i| dp[i][0] = true }
(1..n).each do |i|
(1..target).each do |j|
dp[i][j] = dp[i - 1][j]
if arr[i - 1] <= j
dp[i][j] = dp[i][j] || dp[i - 1][j - arr[i - 1]]
endendend
dp[n][target]
end
coins = [1, 5, 6, 9]
puts "Min coins for 11: #{coin_change(coins, 11)}"
puts "Ways for 10: #{count_ways(coins, 10)}"
arr = [3, 34, 4, 12, 5, 2]
puts "Subset sum 9: #{subset_sum(arr, 9)}"
puts "Subset sum 30: #{subset_sum(arr, 30)}"
Quick answerA Monotonic Stack maintains elements in increasing or decreasing order, enabling O(n) solutions for Next Greater Element and Largest Rectangle in Histogram.
Pop elements violating monotonic property
Next Greater: decreasing stack
Histogram: pop and calculate area when height decreases
Both O(n) time, O(n) space
Crystal
# Monotonic Stack Problems# Next Greater Elementdefnext_greater(arr : Array(Int32))
n = arr.size
result = Array.new(n, -1)
stack = [] of Int32
(0...n).each do |i|
while !stack.empty? && arr[stack.last] < arr[i]
result[stack.pop] = arr[i]
end
stack << i
end
result
end# Largest Rectangle in Histogramdeflargest_rect(heights : Array(Int32))
stack = [] of Int32
max_area = 0
h = heights + [0]
(0...h.size).each do |i|
while !stack.empty? && h[stack.last] > h[i]
height = h[stack.pop]
width = stack.empty? ? i : i - stack.last - 1
area = height * width
max_area = Math.max(max_area, area)
end
stack << i
end
max_area
end
arr = [4, 5, 2, 10, 8]
ng = next_greater(arr)
puts "Next Greater: #{ng.join(" ")}"
h = [2, 1, 5, 6, 2, 3]
puts "Largest Rect: #{largest_rect(h)}"
Quick answerFlood Fill changes all connected same-color pixels. Number of Islands counts connected groups of '1's. Both use DFS with 4-directional traversal.
Mark visited cells to avoid reprocessing
4-directional: up, down, left, right
Time O(R*C), Space O(R*C) recursion stack
Jagged arrays (Array(Array(Char))) for grid
Crystal
# Flood Fill and Number of Islands# Flood Filldefflood_fill(img, r, c, old_color, new_color)
returnif r < 0 || r >= img.size || c < 0 || c >= img[0].size
returnif img[r][c] != old_color || img[r][c] == new_color
img[r][c] = new_color
flood_fill(img, r + 1, c, old_color, new_color)
flood_fill(img, r - 1, c, old_color, new_color)
flood_fill(img, r, c + 1, old_color, new_color)
flood_fill(img, r, c - 1, old_color, new_color)
end# Number of Islandsdefdfs(grid, r, c)
returnif r < 0 || r >= grid.size || c < 0 || c >= grid[0].size
returnif grid[r][c] == '0'
grid[r][c] = '0'
dfs(grid, r + 1, c)
dfs(grid, r - 1, c)
dfs(grid, r, c + 1)
dfs(grid, r, c - 1)
enddefnum_islands(grid)
count = 0
(0...grid.size).each do |r|
(0...grid[0].size).each do |c|
if grid[r][c] == '1'
dfs(grid, r, c)
count += 1endendend
count
end
grid = [
['1', '1', '0', '0'],
['1', '1', '0', '0'],
['0', '0', '1', '0'],
['0', '0', '0', '1']
]
puts "Islands: #{num_islands(grid)}"
Quick answerPrim's Algorithm uses a PriorityQueue as a min-heap. It grows the MST by picking the minimum weight edge connecting visited to unvisited vertices.
Quick answerCycle detection differs for directed and undirected graphs. Directed graphs use DFS with a recursion stack. Undirected graphs use Union-Find.
Quick answerReverse Polish Notation (RPN) evaluation and Infix to Postfix conversion are classic stack problems. Crystal Array and to_i make implementations clean.
RPN: push operands, pop two for operators
Infix to Postfix: shunting-yard algorithm
Precedence function for operator ordering
Used in calculators, compilers, and interpreters
Crystal
# Expression Evaluation using Stack# Evaluate Reverse Polish Notationdefeval_rpn(tokens : Array(String))
stack = [] of Int32
tokens.each do |t|
case t
when"+"
b = stack.pop
a = stack.pop
stack << a + b
when"-"
b = stack.pop
a = stack.pop
stack << a - b
when"*"
b = stack.pop
a = stack.pop
stack << a * b
when"/"
b = stack.pop
a = stack.pop
stack << a // b
else
stack << t.to_i
endend
stack.pop
end# Infix to Postfixdefinfix_to_postfix(expr : String)
ops = [] of Char
result = [] of String
precedence = ->(c : Char) {
case c
when'+', '-'then1when'*', '/'then2else0end
}
expr.each_char do |c|
if c.ascii_number?
result << c.to_s
elsif c == '('
ops << c
elsif c == ')'while ops.last != '('
result << ops.pop.to_s
end
ops.pop
elsewhile !ops.empty? && precedence.call(ops.last) >= precedence.call(c)
result << ops.pop.to_s
end
ops << c
endendwhile !ops.empty?
result << ops.pop.to_s
end
result.join(" ")
end
rpn = ["2", "1", "+", "3", "*"]
puts "RPN eval: #{eval_rpn(rpn)}"
puts "Infix to Postfix: #{infix_to_postfix("(2+3)*4")}"
Quick answerThe Strategy pattern selects an algorithm at runtime. The Template Method defines a skeleton algorithm in a base class with abstract steps.
Quick answerA Sparse Table preprocesses an array in O(n log n) to answer Range Minimum Queries in O(1) time. It exploits overlapping ranges of powers of 2.
Build: precompute minimums for all power-of-2 lengths
Query: use two overlapping ranges that cover [l, r]
How interviewers ask it“Explain advanced Crystal - nilable types and pattern matching in detail — what should a new team member understand about them?”
Crystal is a compiled, statically typed programming language with Ruby-like syntax. It focuses on high performance, developer productivity, and type safety.
What are the main features of Crystal?
Crystal provides static typing with type inference, Ruby-like syntax, object-oriented programming, concurrency using fibers and channels, macros, and native compiled performance.
What is type inference in Crystal?
Type inference allows Crystal to automatically determine variable types at compile time without requiring explicit type declarations in most cases.
What are fibers in Crystal?
Fibers are lightweight concurrent execution units managed by Crystal's runtime. They enable efficient multitasking without the overhead of operating system threads.
What are channels in Crystal?
Channels provide safe communication between fibers, allowing concurrent programs to exchange data without shared memory issues.
What are macros in Crystal?
Macros generate code during compilation, reducing boilerplate and enabling compile-time metaprogramming.
What are shards in Crystal?
Shards are Crystal's dependency management system used to install, manage, and version external libraries and packages.
Is Crystal object-oriented?
Yes. Crystal supports object-oriented programming with classes, modules, inheritance, mixins, encapsulation, and polymorphism.
Where is Crystal commonly used?
Crystal is commonly used for backend web applications, APIs, command-line tools, microservices, and performance-sensitive applications.
Why is Crystal important for technical interviews?
Companies using Crystal may evaluate candidates on language syntax, concurrency, object-oriented programming, type inference, macros, performance optimization, and backend development concepts.
AK
Written and reviewed by Abhishek Kumar
Founder, InterviewPitch · 10+ years in IT. Questions are collected from real interview rounds and refreshed regularly. Spotted an error? Tell us.