Challenge - 5 Problems
Zip Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Zip operation?
Consider the following C# code using Zip to combine two arrays. What will be printed?
C Sharp (C#)
var numbers = new[] {1, 2, 3}; var words = new[] {"one", "two", "three"}; var zipped = numbers.Zip(words, (n, w) => $"{n}-{w}"); foreach (var item in zipped) { Console.WriteLine(item); }
Attempts:
2 left
💡 Hint
Zip pairs elements from two sequences in order.
✗ Incorrect
The Zip method pairs elements from the first and second arrays by index, then applies the lambda to create strings like "1-one".
❓ Predict Output
intermediate2:00remaining
What is the output when sequences have different lengths?
What will this C# code print when using Zip on arrays of different lengths?
C Sharp (C#)
var a = new[] {10, 20, 30, 40}; var b = new[] {"a", "b"}; var zipped = a.Zip(b, (x, y) => $"{x}{y}"); foreach (var s in zipped) Console.WriteLine(s);
Attempts:
2 left
💡 Hint
Zip stops at the shortest sequence length.
✗ Incorrect
Zip pairs elements until one sequence runs out. Here, only first two pairs are zipped.
🔧 Debug
advanced2:00remaining
What error does this Zip code cause?
What error will this C# code produce when run?
C Sharp (C#)
var list1 = new List<int> {1, 2, 3}; List<string> list2 = null; var zipped = list1.Zip(list2, (x, y) => x + y.Length); foreach (var item in zipped) Console.WriteLine(item);
Attempts:
2 left
💡 Hint
Check what happens if one sequence is null.
✗ Incorrect
Calling Zip with a null second sequence causes a NullReferenceException at runtime.
❓ Predict Output
advanced2:00remaining
What is the output of this Zip with index?
What will this C# code print?
C Sharp (C#)
var nums = new[] {5, 10, 15}; var words = new[] {"five", "ten", "fifteen"}; var zipped = nums.Zip(words, (n, w) => $"{w}:{n}"); var indexed = zipped.Select((s, i) => $"{i}-{s}"); foreach (var item in indexed) Console.WriteLine(item);
Attempts:
2 left
💡 Hint
Select with index adds the position before each string.
✗ Incorrect
Zip pairs elements, then Select adds the index before each pair string.
🧠 Conceptual
expert2:00remaining
How many items are in the result of this Zip?
Given these sequences, how many items will the Zip produce?
C Sharp (C#)
var seq1 = Enumerable.Range(1, 100); var seq2 = Enumerable.Range(1, 50); var result = seq1.Zip(seq2, (x, y) => x + y);
Attempts:
2 left
💡 Hint
Zip stops at the shortest sequence length.
✗ Incorrect
Zip produces as many items as the shortest input sequence length, which is 50 here.