- Related Questions & Answers
- Minimum Number of Jumps Problem
- 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
- 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 next greater number with same set of digits in C++
- Check if all people can vote on two machines in Python
- Linked List Jumps in C++
- Check if two String objects have the same value in C#
- Check if sum of divisors of two numbers are same in Python
- Find if two rectangles overlap using C++.
- Program to find number of unique subsequences same as target in C++
- Maximum points collected by two persons allowed to meet once in C++

- 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

Advertisements