Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Coding: Python String and Lists

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Coding: Python String and Lists. Start with the requirements on the right.

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.

Problem

Sony BRAVIA test tooling receives a label string and a sequence of integer measurements. Implement a function that performs four deterministic transformations without changing the original list.

Requirements

  1. Reverse the input string by Unicode code point.
  2. Count ordinary ASCII space characters, " ", in the original string. Do not count tabs or newlines.
  3. Replace every consecutive run of two or more ordinary spaces with exactly one space. Single spaces remain unchanged, and other whitespace is preserved.
  4. Split the integer list into two stable lists: values at even positions first and values at odd positions second. Preserve the relative order within both lists. Position counting is zero-based, and the value itself may be negative or odd/even independently of its position.

Return a dictionary with exactly these keys: reversed, space_count, normalized, even_positions, and odd_positions.

Formal Specification

Input is text: str and values: list[int]. Return dict containing a string, an integer, a string, and two integer lists. The input list must not be mutated.

Constraints

  • 0 <= len(text) <= 10^6
  • 0 <= len(values) <= 10^6
  • -10^9 <= values[i] <= 10^9
  • Only the ASCII space character is counted or normalized
  • The input list must not be mutated

Function Signature

def process_bravia_data(text, values):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output