LeetCode 1699: Number of Calls Between Two Persons Solution

Master LeetCode problem 1699 (Number of Calls Between Two Persons), a medium challenge, with our optimized solutions in Java, C++, and Python. Explore detailed explanations, test your code in our interactive editor, and prepare for coding interviews.

1699. Number of Calls Between Two Persons

Medium

Problem Explanation

Explanation:

To solve this problem, we can simulate the calls between two persons and count the number of calls that occur between them. We can maintain a call log for each person and then iterate through the call logs to find the number of calls that overlap.

Steps:

  1. Create call logs for both persons to store the start and end times of their calls.
  2. Iterate through each call in the first person's call log and check if there are any overlapping calls in the second person's call log.
  3. If there is an overlap, calculate the duration of the overlapping calls.
  4. Sum up the durations of all overlapping calls to get the total number of calls between the two persons.

Time Complexity: O(n*m) where n and m are the number of calls for each person respectively. Space Complexity: O(n+m) to store the call logs for both persons.

:

Solution Code

class Solution {
    public int numberOfCalls(int[][] person1, int[][] person2) {
        int count = 0;
        for (int[] call1 : person1) {
            for (int[] call2 : person2) {
                int start = Math.max(call1[0], call2[0]);
                int end = Math.min(call1[1], call2[1]);
                if (start < end) {
                    count += end - start;
                }
            }
        }
        return count;
    }
}

Try It Yourself

Loading code editor...

Related LeetCode Problems

Frequently Asked Questions

How to solve LeetCode 1699 (Number of Calls Between Two Persons)?

This page provides optimized solutions for LeetCode problem 1699 (Number of Calls Between Two Persons) in Java, C++, and Python, along with a detailed explanation and an interactive code editor to test your code.

What is the time complexity of LeetCode 1699 (Number of Calls Between Two Persons)?

The time complexity for LeetCode 1699 (Number of Calls Between Two Persons) varies by solution. Check the detailed explanation section for specific complexities in Java, C++, and Python implementations.

Can I run code for LeetCode 1699 on DevExCode?

Yes, DevExCode provides an interactive code editor where you can write, test, and run your code for LeetCode 1699 in Java, C++, or Python.

Back to LeetCode Solutions