This problem set evaluates data structures and algorithms competencies, covering mapping and set intersection for pairwise course overlap, permutation and uniqueness constraints for Latin-square validation, and run-length pattern recognition for Nonogram clue matching.
You are given multiple coding questions from an interview. Implement each function as described.
You are given an array of pairs (studentId, courseName) describing which student took which course.
Task: For every pair of distinct students (idA, idB) (where idA < idB), compute the list of course names that both students have taken.
Input:
String[][] enrollments
, where each element is
{studentId, courseName}
.
Output:
"idA,idB"
Example
Input:
[ ["17","Math"], ["17","English"], ["58","Math"], ["61","Physics"] ]
Output (one acceptable format):
(
"17,58" -> ["Math"],
"17,61" -> [],
"58,61" -> []
)
Given an n x n integer grid, validate whether it is a valid Latin-square style grid:
A grid is valid if:
n >= 1
[1, n]
1..n
exactly once
1..n
exactly once
Return true if valid, otherwise false.
Examples
grid = [
[1,2,3],
[2,3,1],
[3,1,2]
]
=> true
grid = [
[0,2,3],
[2,3,1],
[3,1,2]
]
=> false (0 is out of range)
grid = [
[1,3],
[2,1]
]
=> false (3 is out of range for n=2)
A Nonogram board is a R x C grid of characters where each cell is:
'B'
= black
'W'
= white
You are also given:
rowClues
: an array of length
R
, where
rowClues[i]
is a list of run-lengths of consecutive
'B'
groups in row
i
(left to right).
colClues
: an array of length
C
, where
colClues[j]
is a list of run-lengths of consecutive
'B'
groups in column
j
(top to bottom).
Task: Return true if the board matches all row and column clues; otherwise return false.
Notes:
[]
) means there are
no
black cells in that row/column.
Example
matrix = [
[W,W,W,W],
[B,W,W,W],
[B,W,B,B],
[W,W,B,W],
[B,B,W,W]
]
rowClues = [ [], [1], [1,2], [1], [2] ]
colClues = [ [2,1], [1], [2], [1] ]
=> true
If the clues do not match the derived runs, return false.