DEVICE CROSSOVER

CleverTap’s users can access the platform via a website and a mobile app. Every time the user
visits the website/mobile app, we store a timestamp of the visit.

Most of our users access the platform via the website only, however, there are a few who use
both mediums to access it. Given the visit history for a particular user, our product manager
would like to know how many times the user switched devices.

Example 1:
    9 am, 1 Apr - Website #1
    7 pm, 2 Apr - Website #2
    8 pm, 2 Apr - Website #3
    8 am, 7 Apr - App #4
    9 am, 7 Apr - Website #5

In the example above, the user switched devices twice - once from the Website to the App
(#3 to #4), and then from the App back to the Website (#4 to #5).

Example 2:
    1 am, 10 Apr - App #1
    7 pm, 18 Apr - Website #2
    8 pm, 28 Apr - Website #3
    8 am, 29 Apr - App #4
    9 am, 29 Apr - Website #5

In this example, the user switched devices thrice - once from the App to the Website (#1
to#2), and then from the Website to the App (#3 to #4), and finally from the App to the
Website (#4 to #5).

Given an array A of N integers, where each A[i] is the timestamp at which a user visited the website (sorted in ascending
order) and an another integar array B of size M, where each B[j] is the timestamp at which a user visited the app (sorted in ascending
order)

Return the number of switches between platforms.



Input Format

The first argument given is the integer array A.
The second argument given is the integer array B.

Output Format

Return the number of switches between platforms.

Constraints

0 <= N, M <= 10^5
1 <= A[i],B[i] <= 10^7

For Example

Input 1:
    A = [13, 14, 22]
    B = [8, 17]
Output 1:
    3
Explaination 1:
At time 8 user login at App
At time 13 user login at website #switch 1
At time 14 user login at website
At time 17 user login at App     #switch 2
At time 22 user login at website #switch 3

Input 2:
    A = [ ]
    B = [3, 5, 7, 9]
Output 2:
    0
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving DEVICE CROSSOVER on Interview Code Editor
Sign Up
to access hints and editorial solutions for DEVICE CROSSOVER

Discussion


Loading...
Click here to start solving coding interview questions