Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Python String and Armstrong Number

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

Your question is Python String and Armstrong Number. 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

Neudesic data-processing utilities often receive text alongside numeric configuration values. Implement one function that normalizes a text value and finds all Armstrong numbers within a specified range.

Your function must:

  1. Convert alphabetic characters to lowercase.
  2. Replace every non-alphanumeric character with a space.
  3. Collapse consecutive whitespace and remove leading or trailing whitespace.
  4. Reverse the order of the resulting words, without reversing characters within each word.
  5. Return every Armstrong number from 0 through limit, inclusive. A number is an Armstrong number when it equals the sum of each digit raised to the number of digits in the number.

Formal Specification

Input consists of an ASCII string text and a non-negative integer limit. Return a dictionary with two keys: transformed, a string, and armstrong_numbers, a list of integers in ascending order.

Examples

Example 1

Input: text = " Neudesic, Azure Team! ", limit = 500

Output: {"transformed": "team azure neudesic", "armstrong_numbers": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407]}

Punctuation becomes spaces, words are normalized, and their order is reversed.

Example 2

Input: text = "Python## Algorithms", limit = 10

Output: {"transformed": "algorithms python", "armstrong_numbers": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]}

Constraints

  • 0 <= len(text) <= 10^5
  • 0 <= limit <= 10^6
  • text contains ASCII characters only.
  • Armstrong numbers must be returned in ascending order.

Constraints

  • 0 <= len(text) <= 10^5
  • 0 <= limit <= 10^6
  • text contains ASCII characters only
  • Armstrong numbers must be returned in ascending order

Function Signature

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