LeetCode 550: Game Play Analysis IV
Problem Description
Explanation:
To solve this problem, we need to count the number of players who logged in for at least two consecutive days starting from their first login date and then divide that number by the total number of players. We can achieve this by using a SQL query to filter the players who meet the criteria and calculate the fraction as per the given formula.
Here are the steps:
- Use a SQL query to filter the players who logged in on at least two consecutive days starting from their first login date.
- Count the number of players who meet the criteria.
- Calculate the fraction by dividing the count of players meeting the criteria by the total number of players.
Time Complexity: O(n), where n is the number of records in the Activity table. Space Complexity: O(1)
: :
Solutions
# Write your Java solution here
SELECT
ROUND(
SUM(CASE WHEN EXISTS (
SELECT * FROM Activity a2
WHERE a1.player_id = a2.player_id
AND DATEDIFF(a2.event_date, a1.event_date) = 1
) THEN 1 ELSE 0 END) / COUNT(DISTINCT a1.player_id), 2
) AS fraction
FROM Activity a1
Related LeetCode Problems
Loading editor...