Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Reverse Integer Digits and Leap Year

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

Your question is Reverse Integer Digits and Leap Year. 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

Keysight PathWave test automation may process numeric configuration values alongside calendar-based test metadata. Implement a function that reverses the digits of a signed integer and determines whether a given year is a leap year in the Gregorian calendar.

Formal Specification

Given integers number and year, return a dictionary with exactly two entries:

  • reversed: number with its decimal digits reversed. Preserve the sign, and discard leading zeroes in the reversed result.
  • is_leap_year: True if year is a leap year, otherwise False.

A year is a leap year if it is divisible by 400, or if it is divisible by 4 but not by 100. Use arithmetic rather than converting number to a string for the primary solution.

Constraints

  • -10^9 <= number <= 10^9
  • 1 <= year <= 9999
  • The year follows the proleptic Gregorian calendar
  • Python integer arithmetic is sufficient, so overflow handling is not required

Function Signature

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