A Useless Collection of Coding Questions for Large Model Interviews (Part 1) (Gemini 2.5 Pro Translated Version)
When I say “useless,” I mean useless. Even if you know these, you won’t actually be asked them in most interviews.
So why does the article have this crappy title? Because these are the questions I ask in interviews, and based on my experience, 80% of candidates can’t write them out within 30 minutes, even using the most basic methods. Anyone who can write them out using the most basic methods within 30 minutes, I consider to have met the minimum standard for training large models.
Of course, the average Zhihu user can write them in 3 seconds, so please don’t mock how simple the questions are, or how foolish the reference answers might be. In short,
So if you also think these are useless, you are correct.
I. Transpose a nested list Problem:
1
2
3
4
5
6
# Python
# Given a nested list foo = [ [A, B], [C, D] ],
# transpose it to bar = [ [A, C], [B, D] ].
# The nested items can be lists, tuples, or other iterable objects.
# The type of A is arbitrary; it can even be a list.
Reference Answer:
1
bar = list(zip(*foo))
Follow-up Question:
1
# If the sublists in foo have unequal lengths, how should transposition be done according to the longest/shortest sublist?
II. Group tuples in a list Problem:
1
2
3
4
5
6
# Python
# Given a list of tuples foo = [ (A, 1), (B, 2), (C, 2), (D, 1) ],
# group the list by the last element of the tuples into bar = [ [ (A, 1), (D, 1) ], [ (B, 2), (C, 2) ]].
# The length of the tuples is not fixed, and the types of elements within the tuples are also arbitrary.
# Try to use official libraries as much as possible.
Reference Answer:
1
2
3
4
5
6
7
8
9
10
from itertools import groupby
# Sort by the grouping element
sorted_foo = sorted(foo, key=lambda x: x[-1])
# Call the official black magic
grouped_data = groupby(sorted_foo, key=lambda x: x[-1])
# Expand into a list
bar = [ list(f) for _, f in grouped_data ]
Follow-up Question:
1
# How to group based on the type of the last element in the tuple?
III. Pick the median value Problem:
1
2
3
4
5
6
7
8
# Python
# A list contains some float numbers between -10.0 and 10.0,
# and this list also contains some None values.
# For example, foo = [ -1.0, None, 1.0, None, 0.0 ]
# Now, you are required to return the index of the median value after excluding None values.
# For example, in foo, the median is 0.0, so return bar = 4.
# If there is an even number of valid values, take the one corresponding to the upper median index.
Reference Answer:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import numpy
foo = [ -1.0, None, 1.0, None, 0.0 ]
# Count the number of Nones
n_none = foo.count(None)
# Replace None with a large number to ensure it doesn't interfere with the sorting of normal values
foo_fix_none = [255.0 if i is None else i for i in foo]
# Calculate the index based on the count of non-None elements
# (len(foo) - n_none) is the count of valid numbers.
# // 2 gives the index of the median (or lower median for even counts in a 0-indexed array of valid numbers).
# numpy.argsort sorts foo_fix_none and returns an array of indices.
# We pick the index from argsort that corresponds to the median element among valid numbers.
index_of_median_among_valid = (len(foo) - n_none) // 2
bar = numpy.argsort(foo_fix_none)[index_of_median_among_valid]
Follow-up Question:
1
# How to find the indices of the middle K values?
IV. Find the position of a number pattern Problem:
1
2
3
4
5
6
7
# Python
# Given a list containing some positive integers (guaranteed to have only positive integers),
# find the index of the last number 1, with the condition that a number 2 exists after this 1 (existence guaranteed).
# For example, foo = [0, 1, 2, 1, 0, 1, 0, 2, 1, 0],
# then the output should be bar = 5.
# No restrictions on using black magic from various libraries.
Reference Answer:
1
2
3
4
5
6
7
8
9
10
11
12
import numpy
foo = [0, 1, 2, 1, 0, 1, 0, 2, 1, 0]
# Get indices of all 1s, set others to 0.
# This actually yields an array where elements are index if foo[index]==1, else 0.
indices_of_ones_or_zero = numpy.arange(len(foo)) * (numpy.array(foo) == 1)
# Find the index of the last 2
index_of_last_two = numpy.where(numpy.array(foo) == 2)[0][-1]
# Consider only the part of 'indices_of_ones_or_zero' before the last 2.
# Find the maximum index in this part (which corresponds to the last '1' before the last '2').
bar = numpy.max(indices_of_ones_or_zero[:index_of_last_two])
Follow-up Question:
1
# Now there is a 2D numpy array. The above operation is required for each row, but explicit loops cannot be used.
V. Print log ordered by subprocess rank Problem:
1
2
3
4
5
6
7
# Python
# A program starts N subprocesses, and these subprocesses have different ranks from 1 to N.
# A function get_rank() is defined in the program that can return the current subprocess's rank.
# Implement a method foo(bar) such that these subprocesses can print bar in order of their rank.
# The get_rank() function has an embedded barrier feature, ensuring all subprocesses synchronize at this point.
# No need to consider the implementation cost.
Reference Answer:
1
2
3
4
5
6
7
8
9
10
11
12
13
import time
def foo(bar):
# Assuming get_rank() returns an integer or string convertible to int.
# The problem statement says get_rank() returns rank from 1 to N.
# If it's 0-indexed in practice, adjust sleep accordingly (e.g. sleep(rank) or sleep(rank+1) if ranks are 0 to N-1).
# Given "1 to N", rank itself is fine for sleep duration.
rank = int(get_rank())
# Each subprocess sleeps for 'rank' seconds to adjust the order
time.sleep(rank)
print(bar)
Follow-up Question:
1
# How to make these subprocesses write to a log file in order of their rank?
Enjoy Reading This Article?
Here are some more articles you might like to read next: