FastPrepDays Since Last Login ๐Ÿ 
Problems/Days Since Last Login ๐Ÿ 

Days Since Last Login ๐Ÿ 

Alarm.com logoAlarm.comโ— EasyINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

At Alarm.com we need a new piece of functionality that will tell us how many days it's been since a user last logged into our site. Our product manager has given us the following requirements that they would like implemented so that we can start tracking inactive users.

You are given two strings: lastLoginDate, the day the user last logged in, and today, today's date. Both use the format "MM/dd/yyyy". today is passed in so the answer does not depend on when the code runs.

Minimally Viable Product

  • Convert lastLoginDate to a date and subtract it from today.
  • Return the absolute whole number of days as a string, with no leading zeros (for example "0", "1" or "365").

Things to consider (check them in this order)

  • If lastLoginDate is empty or contains only spaces, return the error code "E8430".
  • Otherwise, if lastLoginDate is in the wrong format, return the error code "E9021". The correct format is exactly 10 characters: two digits, /, two digits, /, four digits. Anything else is the wrong format, including one-digit months or days and spaces before or after the date.
  • Otherwise, if lastLoginDate is not a valid date, return the error code "E1756". A valid date has a month from 01 to 12, a day that exists in that month, and a year from 0001 to 9999.

Use the Gregorian leap-year rule for every year: February has 29 days when the year is divisible by 4 but not by 100, or divisible by 400.

Complete the function daysSinceLastLogin in the editor.

daysSinceLastLogin has the following parameters:

  • String lastLoginDate: the last login date to check
  • String today: today's date, always a valid date in the format "MM/dd/yyyy"

The function returns a String: the number of days between the two dates, or one of the error codes above.

Function

daysSinceLastLogin(lastLoginDate: String, today: String) โ†’ String

Examples

Example 1

lastLoginDate = "07/06/2022"today = "07/07/2022"return = "1"

Both strings are valid dates. 07/06/2022 is one day before 07/07/2022, so the answer is "1".

Example 2

lastLoginDate = "02/30/2020"today = "07/07/2022"return = "E1756"

The input "02/30/2020" is in the correct format but is not a valid date, because February does not have 30 days. So the function returns the error code "E1756".

Constraints

  • 0 โ‰ค lastLoginDate.length โ‰ค 20
  • lastLoginDate contains only printable ASCII characters (codes 32 to 126), so the only whitespace is the space character.
  • today.length = 10
  • today is a valid date in the format "MM/dd/yyyy" with a year from 0001 to 9999.

More Alarm.com interview questions

  • Get Average Thermostat Temperature ๐ŸกOA ยท Seen Mar 2023
  • Arrange CoinsOA ยท Seen Mar 2019

Similar questions at other companies

  • Branch with the Most FilesCapital One ยท OACapital One interview questions
  • Robot Stops Left or Right (Forward Deployed Engineer)Boston Consulting Group ยท OABoston Consulting Group interview questions
  • Blood Type Inheritance: Possible Parent GenotypesAbridge ยท OAAbridge interview questions
  • REST API: Highest International StudentsRippling ยท OARippling interview questions
  • Rearrange String by Alternating EndsHudson River Trading ยท OAHudson River Trading interview questions
  • Filter Isolated Interior Signal BitsSEDEMAC ยท OA
  • Scale Ingredient QuantitiesUpstart ยท OAUpstart interview questions
  • Telephone Keypad String EncodingEpic ยท OAEpic interview questions
  • Count Invalid Log GroupsIBM ยท OAIBM interview questions
  • Count Case-Insensitive TripletsTikTok ยท OATikTok interview questions
See Alarm.com hiring insights
Saved
class Solution {
    public String daysSinceLastLogin(String lastLoginDate, String today) {
      // write your code here
    }

}
Checking accountโ€ฆ