Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Reverse String and Character Count

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

Your question is Reverse String and Character Count. 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

Itc Infotech text-processing utilities may need to transform a string while checking how often a selected character appears. Given a string and one character, return the reversed string and the character's occurrence count in that reversed result.

The count must be case-sensitive. Spaces, punctuation, and repeated characters are valid input and must be preserved during reversal.

Formal Specification

Implement reverse_and_count(text, character):

  • text is a non-empty string.
  • character is a string containing exactly one character.
  • Return a dictionary with two fields:
    • reversed: the characters of text in reverse order.
    • count: the number of times character occurs in reversed.

The count should include every matching character, including occurrences separated by spaces or punctuation.

Constraints

  • 1 <= len(text) <= 10^5
  • len(character) = 1
  • text may contain letters, digits, spaces, and punctuation
  • Matching is case-sensitive

Function Signature

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