Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Basic String and Array Coding

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

Your question is Basic String and Array Coding. 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

While validating text and numeric fields in a PTC application, implement one function that reverses a string, counts the frequency of each letter, and swaps two integers without using a third variable.

Formal Specification

Implement process_text_and_swap(text, a, b):

  1. Return the reversed string.
  2. Count alphabetic characters only. Treat uppercase and lowercase letters as the same, and store frequency keys in lowercase. Ignore spaces, digits, punctuation, and other non-letter characters.
  3. Swap a and b without declaring or using a third variable.
  4. Return a dictionary with keys reversed, frequencies, swapped_a, and swapped_b.

The frequencies value must be a dictionary. The order of its keys does not affect correctness.

Constraints

  • 0 <= len(text) <= 10^5
  • Count only characters for which isalpha() returns True.
  • Frequency keys must be lowercase.
  • -10^9 <= a, b <= 10^9
  • The integer swap must not use a third variable.

Function Signature

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