Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Functional Stream Processing

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

Your question is Functional Stream Processing. 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

SberPay receives a collection of payment operations. Build a functional processing pipeline that keeps only completed operations meeting an amount threshold and belonging to an allowed category, then transforms and ranks the results.

Implement process_operations(operations, min_amount, allowed_categories).

Formal Specification

  • operations is a list of dictionaries. Each dictionary contains:
    • id: a unique string
    • amount: a non-negative number
    • status: a string such as "completed" or "declined"
    • category: a string
  • min_amount is a non-negative number. The threshold is inclusive.
  • allowed_categories is a list of strings.
  • Return a new list of dictionaries containing only id, amount, and category.
  • Include operations where status == "completed", amount >= min_amount, and category is allowed.
  • Sort the result by decreasing amount. For equal amounts, sort by increasing id.
  • Do not modify the input list or its dictionaries. Use functional stream operations such as filter, map, and sorted.

Constraints

  • 0 <= len(operations) <= 10^5
  • 0 <= operation.amount, min_amount <= 10^9
  • Each operation contains id, amount, status, and category
  • Operation identifiers are unique strings

Function Signature

def process_operations(operations, min_amount, allowed_categories):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output