Skip to main content

Golf | LKDNGOLF | May Challenge 2021 Division 2 & 3 | Codechef Solution | Latest Video Solution code

 

It's a lockdown. You’re bored in your house and are playing golf in the hallway.

The hallway has N+2 tiles numbered from 0 to N+1 from left to right. There is a hole on tile number x. You hit the ball standing on tile 0. When you hit the ball, it bounces at lengths of k, i.e. the tiles covered by it are 0,k,2k,, and so on until the ball passes tile N+1.

If the ball doesn't enter the hole in the first trial, you try again but this time standing on the tile N+1. When you hit the ball, it bounces at lengths of k, i.e. the tiles covered by it are (N+1),(N+1k),(N+12k),, and so on until the ball passes tile 0.

Find if the ball will enter the hole, either in its forward journey or backward journey.

Note: The input and output of this problem are large, so prefer using fast input/output methods.

Input

  • The first line contains an integer T, the number of test cases. Then the test cases follow.
  • The only line of each test case contains three integers N,x,k.

Output

Output in a single line, the answer, which should be "YES" if the ball enters the hole either in the forward or backward journey and "NO" if not.

You may print each character of the string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).

Constraints

  • 1T105
  • 1x,kN109

Subtasks

Subtask #1 (10 points): N102

Subtask #2 (90 points): original constraints

Sample Input

3
5 4 2
5 3 2
5 5 2

Sample Output

YES
NO
NO
For Solution
Golf | LKDNGOLF | May Challenge 2021 Division 2 & 3 | Codechef Solution | Latest Video Solution code

Fullfill the Given Condition, and DM the Screenshot on Telegram or Instagram, We will provide the Code there, we are not Charging any kind of Money, so Keep in Mind. Don't Give Money to Anyone

Follow All :- 

SUBSCRIBE The Youtube Channel and Press the Bell Icon
Website :- https://codedelhi.blogspot.com
Telegram  :- https://t.me/EngineerDelhi
Facebook :- https://www.facebook.com/EngineerDelhi
Instagram :- https://www.instagram.com/engineerdelhi

Explanation

In each test case, the tiles covered by the ball for N=5 and k=2 are {0,2,4,6} in the forward journey and {6,4,2,0} in the backward journey.

Therefore, the answer for the first test case is "YES" since the ball falls in the position of the hole at tile 4. But the answer for test cases 2 and 3 is "NO" since the ball does not fall in the position of the hole.


Popular posts from this blog

LeetCode 2583: Kth Largest Sum in a Binary Tree – Solution Explained

When working with binary trees, one common task is to analyze the properties of the tree's levels. In this blog post, we'll walk through a solution to LeetCode Problem 2583: Kth Largest Sum in a Binary Tree , a problem that challenges us to compute and find specific sums from different levels of a binary tree. Problem Statement You are given the root of a binary tree and a positive integer k . Your goal is to return the k-th largest level sum in the tree. The level sum is defined as the sum of the values of all nodes at the same depth in the tree. If the number of levels in the tree is less than k , the function should return -1 . Example 1: Input: root = [5, 8, 9, 2, 1, 3, 7, 4, 6] , k = 2 Output: 13 Explanation: Level 1 sum: 5 Level 2 sum: 8 + 9 = 17 Level 3 sum: 2 + 1 + 3 + 7 = 13 Level 4 sum: 4 + 6 = 10 The 2nd largest sum is 13 . Example 2: Input: root = [1, 2, null, 3] , k = 1 Output: 3 Explanation: The largest level sum is 3 (at the third level). This problem essentia

BCA 5th and 6th Semester Project | BCSP-064 | Synopsys and Project | Both | IGNOU BCA | 100% Accepted | July 2023 and Jan 2024

 Synopsys and Project | Both | July 2023 and Jan 2024 Title of the Project : - PRODUCT HUB Buy it from here (Synopsis + Project) : Synopsis Content :- Synopsis : An overview of the entire project, summarizing its main objectives, scope, and outcomes. Introduction : Introduce the project and provide context for the reader by explaining the problem or need that the project aims to address. Aim and Objective : Clearly state the goals and objectives of the project, outlining what you intend to achieve through its completion. Project Category : Define the domain or category to which the project belongs, helping readers understand the context and purpose of the project. Tools and Platform : List the software tools, programming languages, and platforms you'll be using to develop and implement the project. System Analysis : Discuss the preliminary analysis phase of the project, where you identify requirements,

Maximizing Distance in Arrays | LeetCode Problem 624 | Leetcode Daily Question

LeetCode Problem 624, titled "Maximum Distance in Arrays," challenges us to find the maximum distance between any two elements from different arrays within a given list of arrays. In this blog post, we will break down the problem, explain the code solution step-by-step, and discuss the time and space complexity of the solution. Problem Explanation The problem presents us with a 2D array where each sub-array is sorted in ascending order. Our task is to determine the maximum distance between any two elements such that the elements come from different sub-arrays. Code Explanation Here's a clean and efficient solution to the problem using C++:     class Solution {     public:         int maxDistance ( vector < vector < int >> & arrays )         {             int min_value = arrays [ 0 ][ 0 ];             int max_value = arrays [ 0 ][ arrays [ 0 ]. size () - 1 ];             int maximum_distance = 0 ;             for ( int i = 1 ; i <