Gardening Friends solution codeforces

Two friends, Alisa and Yuki, planted a tree with nn vertices in their garden. A tree is an undirected graph without cycles, loops, or multiple edges. Each edge in this tree has a length of kk. Initially, vertex 11 is the root of the tree. Alisa and Yuki are growing the tree not just for fun, they want to sell … Read more

Magic Triples (Easy Version) solution codeforces

Magic Triples (Easy Version) time limit per test 4 seconds memory limit per test 256 megabytes This is the easy version of the problem. The only difference is that in this version, ai≤106ai≤106. For a given sequence of nn integers aa, a triple (i,j,k)(i,j,k) is called magic if: 1≤i,j,k≤n1≤i,j,k≤n. ii, jj, kk are pairwise distinct. there exists a positive integer bb such that ai⋅b=ajai⋅b=aj and aj⋅b=akaj⋅b=ak. Kolya received a sequence of … Read more

Magic Triples (Hard Version) solution codeforces

Magic Triples (Hard Version)time limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is the hard version of the problem. The only difference is that in this version, ai≤109. For a given sequence of n integers a, a triple (i,j,k) is called magic if: 1≤i,j,k≤n.i, j, k are pairwise distinct.there exists a positive integer … Read more

Sliding Subarray Beauty solution leetcode

Sliding Subarray Beauty solution leetcode User Accepted:3303 User Tried:7764 Total Accepted:3451 Total Submissions:19531 Difficulty:Medium Given an integer array nums containing n integers, find the beauty of each subarray of size k. The beauty of a subarray is the xth smallest integer in the subarray if it is negative, or 0 if there are fewer than x negative integers. Return an integer array containing n – k + 1 integers, which denote the beauty of the subarrays in order from … Read more

Minimum Number of Operations to Make All Array Elements Equal to 1 solution leetcode

Minimum Number of Operations to Make All Array Elements Equal to 1 solution leetcode User Accepted:2210 User Tried:4950 Total Accepted:2401 Total Submissions:10430 Difficulty:Medium You are given a 0-indexed array nums consisiting of positive integers. You can do the following operation on the array any number of times: Select an index i such that 0 <= i < n – 1 and replace either of nums[i] or nums[i+1] with their gcd value. … Read more

Sum Multiples solution leetcode-Given a positive integer n, find the sum of all integers in the range [1, n] inclusive that are divisible by 3, 5, or 7.

Sum Multiples solution leetcode User Accepted:11227 User Tried:11328 Total Accepted:11487 Total Submissions:13365 Difficulty:Easy Given a positive integer n, find the sum of all integers in the range [1, n] inclusive that are divisible by 3, 5, or 7. Return an integer denoting the sum of all numbers in the given range satisfying the constraint.   Example 1:Sum Multiples solution leetcode Input: n = 7 … Read more

Calculate Delayed Arrival Time solution leetcode

Calculate Delayed Arrival Time User Accepted:11361 User Tried:11507 Total Accepted:12099 Total Submissions:14615 Difficulty:Easy You are given a positive integer arrivalTime denoting the arrival time of a train in hours, and another positive integer delayedTime denoting the amount of delay in hours. Return the time when the train will arrive at the station. Note that the time in this problem is … Read more

Buffer Sharing in Multi-tenant Database Environment solution

Buffer Sharing in Multi-tenant Database Environment solution A database is a warehouse where data is organized, stored, and managed by its underlying data structures. Everyone uses some kind of a database. Some cloud service providers decide to build single instances of database management systems which are shared by multiple customers and isolated among different users. … Read more

[Solution] Buffer Sharing in Multi-tenant Database Environment solution codeforces

Buffer Sharing in Multi-tenant Database Environment solution codeforces A database is a warehouse where data is organized, stored, and managed by its underlying data structures. Everyone uses some kind of a database. Some cloud service providers decide to build single instances of database management systems which are shared by multiple customers and isolated among different … Read more

[Solution] Make Them Alike Solution Codechef

[Solution] Make Them Alike Solution Codechef You are given a permutation �P of length �N, an array �A of size �N, and an integer �M. Initially, 0≤��≤�0≤Ai​≤M. Consider an array �′A′ obtained from �A by replacing all zeros in �A with positive integers less than equal to �M. The array �′A′ will then be transformed as follows, in �N steps: In the ��ℎith step, we set ��′=���′Ai′​=APi​′​. The initial array �′A′ is said to be beautiful, if, after the transformation of �N steps, all elements of array �′A′ are equal. … Read more