Hi All,
I just completed my code signal round for visa. It had 4 questions, 2 easy, 1 medium and 1 hard. The trick is to quickly solve the easy ones first, go for medium, and then spend as much time as possible on the hard one.
Question 1 an 2 - Easy
Question 3 - Heavy verbose and hard
Question 4 - Meadium
I completed 1 and 2, then went for 4 and finally 3.
Here are the questions:
Q1(Easy): Count triplets in a string. Rule: If the first and last character of a triple substring is same count += 1
Input -> Output
text = "" -> 0
text = "abc" -> 1
text = "abcxccc" -> 2Q2(Easy): Given a an array of integers, keep adding each digits of the numbers until its one digit. Return the max of each of this results
Example:
[123, 456, 789, 101]
# first round -> 1+2+3 4+5+6 7+8+9 1+0+1 -> 6, 15, 24, 2
# second round -> 6 1+5 2+4 2 -> 6, 6, 6, 2
# max = 6 -> output = 6
Q3(Hard): There are N centers, each with a fixed processing capacity.
A log of events arrives:
"PACKAGE" → send 1 package to the next open center (cyclic order).
A center can handle only capacity[i] packages before needing a reset.
"CLOSURE j" → center j becomes permanently closed.
Key rule:
After attempting a full rotation (i.e., checking all centers without finding one with remaining capacity),
→ reset all open centers to full capacity.
Return the index of the center that processed the most packages.
If tied → return the highest index.
Example
centerCapacities = [1,2,1,2,1]
dailyLog = [
"PACKAGE",
"PACKAGE",
"CLOSURE 2",
"PACKAGE",
"CLOSURE 3",
"PACKAGE",
"PACKAGE"
]
Output: 1Q4(Medium).A sawtooth subarray is a contiguous sequence where parity strictly alternates between even and odd.
Count how many such subarrays exist (length ≥ 1).
Input: [1,3,5,7,9]
Output: 5
# Only single-element subarrays qualify (all odd → no alternation)
Input: [1,2,1,2,1]
Output: 15
# Entire array alternates → all subarrays are valid (n*(n+1)/2)
Input: [1,2,3,7,6,5]
Output: 12
# Alternation breaks at (3,7)