Problem · String

Maximum Positive Feedback

Learn this problem
MediumTiktok logoTiktokOA
See Tiktok hiring insights

Problem statement

The other quesiton in the same batch was posted on our Discord server oa-update channel.

The TikTok Content creator's videos receives feedback from viewers over time, represented as a binary string, videoFeedback:

  • 1 indicates positive reactions(likes, shares, or comments).
  • 0 indicates negative reactions(skips or dislikes).
  • The creator wants to improve a video's overall positive reception by strategically targeting a portion of the video for editing or improvement. Here's the strategy:

  • Choose one specific segment of the video(interval [i, j]) to leave unchanged, where i > 0 and j < videoFeedback_size.
  • Outside this segment, the plan is to completely change the content—flipping negative reactions to positive(0 to 1) and positive reactions to negative(1 to 0).
  • The objective is to maximize the total positive feedback(1s) for the entire video after performing this operation.

    Note: The operation must be performed only once.

    Function

    getMaxPositiveFeedback(videoFeedback: String) → int

    Complete the function getMaxPositiveFeedback in the editor.

    getMaxPositiveFeedback has the following parameter:

    • string videoFeedback: a binary string representing the feedback on a video, where 1 represents positive feedback and 0 represents negative reaction

    Examples

    Example 1

    videoFeedback = "100110"return = 5
    Given videoFeedback_size = 6 and videoFeedback = "100110", The interval i = 4 to j = 5 can be selected as the unchanged segment of the video. Flipping the bits from index 1 to 3 transforms the string from "100110" to "011110". Next, flipping the bit at index 6 (i.e., the last bit) changes the string from "011110" to "011111". As this string contains 5 ones, the output should be 5. There are no intervals that produce an output greater than 5.

    More Tiktok problems

    drafts saved locally
    public int getMaxPositiveFeedback(String videoFeedback) {
      // write your code here
    }
    
    videoFeedback"100110"
    expected5
    checking account