Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Fibonacci and Palindrome Programs

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

Your question is Fibonacci and Palindrome Programs. 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

Cyient engineering utilities may need both sequence generation and text validation. Implement one function that computes a Fibonacci value and determines whether a supplied string is a palindrome.

Formal Specification

Write fibonacci_and_palindrome(n, text), where n is a non-negative integer and text is a string. Return a two-element list [fib_value, is_palindrome].

Use the definition F(0) = 0, F(1) = 1, and F(n) = F(n - 1) + F(n - 2). The palindrome check is case-sensitive and must compare every character exactly as supplied, including spaces and punctuation. Do not create a reversed copy of the string.

Constraints

  • 0 <= n <= 10,000
  • 0 <= len(text) <= 100,000
  • The palindrome check is case-sensitive
  • Spaces and punctuation are treated as ordinary characters
  • Do not construct a reversed copy of text

Function Signature

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