A music streaming platform wants to analyze user listening sessions to tell apart two playback modes: Shuffle Mode and Random Mode. Your job is to decide whether a given listening history could have been produced by Shuffle Mode.
The modes are defined as follows:
You are provided with allSongs, an array containing every unique track in the library, and playlist, the sequence of songs a user actually heard. You may assume the user could have started listening partway through a permutation and stopped at any point.
Return true if the playlist sequence could be a contiguous subsequence taken from a Shuffle Mode session; otherwise, return false.
1 ≤ allSongs.length ≤ 1001 ≤ playlist.length ≤ 100allSongs is a unique, non-empty string.playlist exists in allSongs.Example 1
allSongs = ["A", "B", "C"], playlist = ["A", "B", "C", "A", "C", "B"]
true
The listening history can be split into two complete, valid permutations: The first segment, ["A", "B", "C"], contains each distinct song exactly once. The second segment, ["A", "C", "B"], is another valid permutation. Since the entire sequence follows the rules of shuffle mode, the result is true.
Example 2
allSongs = ["A", "B", "C"], playlist = ["A", "B", "C", "C"]
true
Example 3
allSongs = ["A", "B", "C"], playlist = ["A", "B", "C", "C", "C"]
false