Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Split Array Into Chunks
00:00
5 left

Split Array Into Chunks

EasyPython

Problem

Wissen Technology processes ordered event records in batches. Given an array and a positive chunk size, split the array into consecutive, non-empty chunks while preserving the original order and leaving the input array unchanged.

Formal Specification

Implement split_into_chunks(records, chunk_size).

  • records is a Python list containing arbitrary values.
  • chunk_size is a positive integer.
  • Return a list of lists, where each inner list contains at most chunk_size consecutive elements from records.
  • Every input element must appear exactly once in the output, in the same order.
  • The final chunk may contain fewer than chunk_size elements.
  • Return an empty list when records is empty.

Examples

Example 1

Input: records = [1, 2, 3, 4, 5, 6, 7], chunk_size = 3
Output: [[1, 2, 3], [4, 5, 6], [7]]

The first two chunks contain three elements, and the remaining element forms the final chunk.

Example 2

Input: records = ["a", "b"], chunk_size = 5
Output: [["a", "b"]]

Because the requested size exceeds the array length, the entire array becomes one chunk.

Constraints

  • 0 <= len(records) <= 10^5
  • 1 <= chunk_size <= 10^5
  • Elements may be any Python values.
  • Do not modify records.

Constraints

  • 0 <= len(records) <= 10^5
  • 1 <= chunk_size <= 10^5
  • Elements may be any Python values
  • The input list must not be modified

Function Signature

def split_into_chunks(records, chunk_size):
Interviewer

Your question is Split Array Into Chunks. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.