[AtCoder] C - Tak and CardsRead more
[Codeforces] Round #611 (Div. 3) C. Friends and GiftsRead more
[Codeforces] Round #612 (Div. 2) B. HypersetRead more
[Codeforces] Round #617 (Div. 3) C. Yet Another Walking RobotRead more
[Codeforces] Round #617 (Div. 3) D. Fight with MonstersRead more
[Codeforces] Round #618 (Div. 1) A. Anu Has a FunctionRead more
[LeetCode] Three Equal Parts

927. Three Equal Parts

You are given an array arr which consists of only zeros and ones, divide the array into three non-empty parts such that all of these parts represent the same binary value.

If it is possible, return any [i, j] with i + 1 < j, such that:

  • arr[0], arr[1], …, arr[i] is the first part,
    varr[i + 1], arr[i + 2], …, arr[j - 1] is the second part, and
  • arr[j], arr[j + 1], …, arr[arr.length - 1] is the third part.
  • All three parts have equal binary values.

If it is not possible, return [-1, -1].

Note that the entire part is used when considering what binary value it represents. For example, [1,1,0] represents 6 in decimal, not 3. Also, leading zeros are allowed, so [0,1,1] and [1,1] represent the same value.

Read more
[LeetCode] Card Flipping Game

822. Card Flipping Game

You are given two 0-indexed integer arrays fronts and backs of length n, where the ith card has the positive integer fronts[i] printed on the front and backs[i] printed on the back. Initially, each card is placed on a table such that the front number is facing up and the other is facing down. You may flip over any number of cards (possibly zero).

After flipping the cards, an integer is considered good if it is facing down on some card and not facing up on any card.

Return the minimum possible good integer after flipping the cards. If there are no good integers, return 0.

Read more
[LeetCode] Masking Personal Information

831. Masking Personal Information

You are given a personal information string s, representing either an email address or a phone number. Return the masked personal information using the below rules.

Email address:

An email address is:

  • A name consisting of uppercase and lowercase English letters, followed by
  • The ‘@’ symbol, followed by
  • The domain consisting of uppercase and lowercase English letters with a dot ‘.’ somewhere in the middle (not the first or last character).

To mask an email:

  • The uppercase letters in the name and domain must be converted to lowercase letters.
  • The middle letters of the name (i.e., all but the first and last letters) must be replaced by 5 asterisks “*“.

Phone number:

A phone number is formatted as follows:

  • The phone number contains 10-13 digits.
  • The last 10 digits make up the local number.
  • The remaining 0-3 digits, in the beginning, make up the country code.
  • Separation characters from the set {‘+’, ‘-‘, ‘(‘, ‘)’, ‘ ‘} separate the above digits in some way.

To mask a phone number:

  • Remove all separation characters.
  • The masked phone number should have the form:
  • "***-***-XXXX" if the country code has 0 digits.
  • "+*-***-***-XXXX" if the country code has 1 digit.
  • "+**-***-***-XXXX" if the country code has 2 digits.
  • "+***-***-***-XXXX" if the country code has 3 digits.
  • “XXXX” is the last 4 digits of the local number.
Read more
[LeetCode] Triples with Bitwise AND Equal To Zero

982. Triples with Bitwise AND Equal To Zero

Given an integer array nums, return the number of AND triples.

An AND triple is a triple of indices (i, j, k) such that:

  • 0 <= i < nums.length
  • 0 <= j < nums.length
  • 0 <= k < nums.length
  • nums[i] & nums[j] & nums[k] == 0, where & represents the bitwise-AND operator.
Read more