## Category Archives: Algorithm

### Leetcode 2429 – Minimize XOR

Source: https://leetcode.com/problems/minimize-xor/ Problem statement Given two positive integers num1 and num2, find the integer x such that: x has the same number of set bits as num2, and The value x XOR num1 is minimal. Note that XOR is the bitwise XOR operation. Return the integer x. The test cases are generated such that x…

### Leetcode 39 – Combination Sum

Source: https://leetcode.com/problems/combination-sum/ Problem statement Given an array of distinct integers candidates and a target integer target, return a list of all unique combinations of candidates where the chosen numbers sum to target. You may return the combinations in any order. The same number may be chosen from candidates an unlimited number of times. Two combinations…

### Leetcode 30 – Substring with concatenation of all words

Source: https://leetcode.com/problems/substring-with-concatenation-of-all-words/ Problem statement You are given a string s and an array of strings words. All the strings of words are of the same length. A concatenated substring in s is a substring that contains all the strings of any permutation of words concatenated. For example, if words = [“ab”,”cd”,”ef”], then “abcdef”, “abefcd”, “cdabef”,…

### Educational Codeforces Round 129 – Problem C

You are given two arrays a and b, both consisting of n integers. In one move, you can choose two indices i and j (1≤i,j≤n; i≠j) and swap ai with aj and bi with bj. You have to perform the swap in both arrays. You are allowed to perform at most 104 moves (possibly, zero)….

### Educational Codeforces Round 129 – Problem B

Monocarp has just learned a new card trick, and can’t wait to present it to you. He shows you the entire deck of n cards. You see that the values of cards from the topmost to the bottommost are integers a1,a2,…,an, and all values are different. Then he asks you to shuffle the deck m…

### Educational Codeforces Round 129 – Problem A

Alice and Bob play a game. Alice has n cards, the i-th of them has the integer ai written on it. Bob has m cards, the j-th of them has the integer bj written on it. On the first turn of the game, the first player chooses one of his/her cards and puts it on…

### Codeforces Round #793 – Problem C

C. LIS or Reverse LIS? time limit per test: 1 second memory limit per test: 256 megabytes input: standard input output: standard output You are given an array a of n positive integers. Let LIS(a) denote the length of longest strictly increasing subsequence of a. For example, LIS([2,1,1,3]) = 2. LIS([3,5,10,20]) = 4. LIS([3,1,2,4]) =…

### Codeforces Round #793 – Problem B

B. AND Sorting time limit per test: 1 second memory limit per test: 256 megabytes input: standard input output: standard output You are given a permutation p of integers from 0 to n−1 (each of them occurs exactly once). Initially, the permutation is not sorted (that is, pi>pi+1 for at least one 1≤i≤n−1). The permutation…

### Codeforces Round #793 – Problem A

A. Palindromic Indices time limit per test: 1 second memory limit per test: 256 megabytes input: standard input output: standard output You are given a palindromic string s of length n. You have to count the number of indices i (1≤i≤n) such that the string after removing si from s still remains a palindrome. For…

### Google CodeJam 2022 – Qualification – 4. Chain Reaction

Problem Wile lives alone in the desert, so he entertains himself by building complicated machines that run on chain reactions. Each machine consists of N modules indexed 1,2,…,N. Each module may point at one other module with a lower index. If not, it points at the abyss. Modules that are not pointed at by any others are called initiators….