Reverse Shuffle Merge

Sort by

recency

|

216 Discussions

|

  • + 0 comments

    I still don't understand how when, string = "abcdefgabcdefg" then "agfedcb" is the lexicographically smallest. All my approaches give me"abcdefg". Like it is actually genuinely frustrating how it is messing with my mind. I truly hate this question for wasting my time as I don't even feel like I am learning anything here, just trying to understand the question itself is driving me insane.

  • + 0 comments

    If a secure and reliable gaming experience is what you’re after, BanzaiBet is the perfect choice. Their platform ensures safety with trusted payment methods like mobile and cryptocurrency options, which you can learn more about by visiting https://banzaibet-bd.com/ ,great platform. What’s more, their collection of slots is impressive, featuring themes inspired by everything from timeless classics to popular movies and video games. It’s a great spot for anyone

  • + 1 comment

    O(n) time complexity because even with nested while loop an element of s is only pushed and popped a maximum of 1 times

    from collections import Counter
    
    def reverseShuffleMerge(s):
        char_counts = Counter(s)
        required = Counter()
        for key, value in char_counts.items():
            required[key] = value // 2
        last_char = s[-1]
        char_counts[last_char] -= 1
        required[last_char] -= 1
        result = [last_char]
        for i in range(len(s)-2, -1, -1):
            char = s[i]
            char_counts[char] -= 1
            if not required[char]:
                pass
            elif (not result) or (char >= result[-1]):
                result.append(char)
                required[char] -= 1
            else:
                while result and char < result[-1] and char_counts[result[-1]] >= required[result[-1]] +1:
                    old_char = result.pop(-1)
                    required[old_char] += 1
                result.append(char)
                required[char] -= 1
        return "".join(result)
    
  • + 0 comments

    I hate problems that require you to reread 50 times to just understand what they are asking you to do.

  • + 0 comments

    Worst problem statement ever. Unclear