Company: Tik Tok
Difficulty: medium
TikTok uses a sophisticated algorithm to promote viral content. This algorithm relies on specific \'Viral Factors\' that measure the level of engagement a post receives. A key part of this engagement is determined by the post\'s spikeSpread , which measures the gap between engagement spikes. You are given an array activityIndex of length n representing the activity score of each of the n posts. The engagement pattern of each post is represented by the binary form of its activityIndex , where each \'set-bit\' indicates an engagement spike. The spikeSpread of a post is defined as the maximum gap between any two consecutive engagement spikes. For example, let\'s say a post with activityIndex = 75 is given, then its engagement pattern (75 in binary) is 1001011 . The maximum gap between consecutive engagement spikes = max(2, 1, 0) = 2 . Thus, the spikeSpread/activityIndex = 75 is 2. Input Format Given the array activityIndex of length n , and an integer k , sort the posts in decreasing orde