[LeetCode] Maximize the Confusion of an Exam

2024. Maximize the Confusion of an Exam

A teacher is writing a test with n true/false questions, with ‘T’ denoting true and ‘F’ denoting false. He wants to confuse the students by maximizing the number of consecutive questions with the same answer (multiple trues or multiple falses in a row).

You are given a string answerKey, where answerKey[i] is the original answer to the ith question. In addition, you are given an integer k, the maximum number of times you may perform the following operation:

  • Change the answer key for any question to ‘T’ or ‘F’ (i.e., set answerKey[i] to ‘T’ or ‘F’).

Return the maximum number of consecutive ‘T’s or ‘F’s in the answer key after performing the operation at most k times.

Read more
[Codeforces] Round #775 (Div. 1, based on Moscow Open Olympiad in Informatics) A. Weird SumRead more
[Hacker Rank] Reverse Shuffle MergeRead more
[Hacker Rank] Highest Value PalindromeRead more
[Hacker Rank] Lily`s HomeworkRead more
[Hacker Rank] 3D Surface AreaRead more
[Hacker Rank] The Longest Common SubsequenceRead more
[Hacker Rank] AbbreviationRead more
[LeetCode] Maximum Absolute Sum of Any Subarray

1749. Maximum Absolute Sum of Any Subarray

You are given an integer array nums. The absolute sum of a subarray [numsl, numsl+1, …, numsr-1, numsr] is abs(numsl + numsl+1 + … + numsr-1 + numsr).

Return the maximum absolute sum of any (possibly empty) subarray of nums.

Note that abs(x) is defined as follows:

  • If x is a negative integer, then abs(x) = -x.
  • If x is a non-negative integer, then abs(x) = x.
Read more
[LeetCode] Shortest Word Distance III

245. Shortest Word Distance III

Given an array of strings wordsDict and two strings that already exist in the array word1 and word2, return the shortest distance between these two words in the list.

Note that word1 and word2 may be the same. It is guaranteed that they represent two individual words in the list.

Read more