Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Palindrome and Prime Coding

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

Your question is Palindrome and Prime 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

In a PTC Creo utility, implement a function that validates a string label and prepares a list of prime numbers for numeric configuration checks. The label is a palindrome only when it reads identically from left to right and right to left, with case and all characters preserved.

Return both results from one function.

Formal Specification

Implement palindrome_and_primes(s, limit):

  1. s is a non-empty string. Return whether s is an exact palindrome as a Boolean.
  2. limit is a non-negative integer. Return every prime number from 2 through limit, inclusive, in ascending order.
  3. Return a dictionary with keys is_palindrome and primes.
  4. A prime number is an integer greater than 1 with exactly two positive divisors.

Use the Sieve of Eratosthenes to generate the primes efficiently.

Constraints

  • 1 <= len(s) <= 10^5
  • 0 <= limit <= 10^6
  • The palindrome check is case-sensitive
  • Spaces and punctuation are treated as ordinary characters

Function Signature

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