- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

In this problem, we are given four integers denoting the starting points and jumps taken by each in the race. Our task is to *find if two people ever meet after same number of jumps. *

* *

**Problem Description: **Here, we need to check if two persons starting at points p1 and p2 taking jumps j1 and j2 will be at some point in the path or not.

**Input: **p1 = 5, p2 = 9, j1 = 4, j2 = 2

**Output: **Yes

**Explanation:**

After first jump, p1 = 9, p2 = 11

After second jump, p1 = 13, p2 = 13

**Solution Approach: **

For meeting at some point both the people will have to jump different distances. Here are some conditions that are to be meet to check if the meet of people is possible,

If p1 > p2 then s1 needs to be less than s2.

And ( (p2 - p1) % (s1 - s2) ) == 0

Then the meeting is possible otherwise not possible.

#include<iostream> using namespace std; bool WillMeet(int p1, int j1, int p2, int j2){ return ( (j1 > j2 && ( ((p2 - p1) % (j1 - j2)) == 0)) || (j2 > j1 && ( ((p1 - p2) % (j2 - j1)) == 0)) ); } int main() { int p1 = 5, j1 = 4, p2 = 9, j2 = 2; if(WillMeet(p1, j1, p2, j2)) cout<<"Both will meet at some point"; else cout<<"Both will not meet at any point"; return 0; }

Both will meet at some point

- Related Questions & Answers
- Program to find minimum cost to send same number of people to two different cities in Python
- Minimum Number of Jumps Problem
- Find the Number of Ways to Pair People using C++
- Find the number of jumps to reach X in the number line from zero in C++
- Check if it is possible to reach a number by making jumps of two given length in Python
- Program to check two spheres can ever meet by accelerating or not in a 3D space in Python
- Meta Strings (Check if two strings can become same after a swap in one string) in C++
- Number of Ways to Stay in the Same Place After Some Steps in C++
- C Program for Minimum number of jumps to reach the end
- Check if a number has same number of set and unset bits in C++
- Find the Number of Triangles After N Moves using C++
- Program to find minimum number of people to teach in Python
- Find next greater number with same set of digits in C++
- Check if all people can vote on two machines in Python
- How to find the number of rows in a data.table where two or more column values meet a criteria in R?

Advertisements