Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Reverse String and Unique Values

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

Your question is Reverse String and Unique Values. 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

For a Tata Consultancy Services North America data-validation utility, process a string and a Python dictionary in one function. Return the string reversed and the dictionary values deduplicated while preserving the order of their first occurrence.

Formal Specification

Implement reverse_and_unique_values(text, data).

  • text is a string. Return its characters in reverse order.
  • data is a dictionary whose keys and values are strings. Examine values in normal dictionary iteration order.
  • Return a dictionary with two entries: reversed_text, containing the reversed string, and unique_values, containing a list of distinct values in first-seen order.
  • Treat values as equal when their string contents are equal.

Constraints

  • 0 <= len(text) <= 10^5
  • 0 <= len(data) <= 10^5
  • Every dictionary key and value is a string
  • Dictionary insertion order must be preserved

Function Signature

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