Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Python Coding: Primes and Counts

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

Your question is Python Coding: Primes and Counts. 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

A GlobalLogic data-quality pipeline receives a batch of integers and a compact status string. Implement one Python function that identifies which integers are prime and counts how many times each character appears in the string.

Return a dictionary with two keys:

  1. prime_flags: a list of booleans aligned with the input integer array. A value is true only when the corresponding integer is prime.
  2. character_counts: a dictionary mapping each distinct character to its frequency. Preserve the order in which characters first appear.

Treat all integers less than 2 as non-prime. The input string contains lowercase English letters and is non-empty.

Formal Specification

  • Input: numbers, a list of integers, and text, a non-empty string.
  • Output: a dictionary with prime_flags: list[bool] and character_counts: dict[str, int].
  • A prime number is an integer greater than 1 with no positive divisors other than 1 and itself.

Constraints

  • 1 <= len(numbers) <= 10^4
  • -10^9 <= numbers[i] <= 10^9
  • 1 <= len(text) <= 10^5
  • text contains only lowercase English letters

Function Signature

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