Starting Point | Practice | GeeksforGeeks

You are a traveler, lost in a jungle. Backtrack your steps and find the starting point. 
Currently, you are at coordinates (x,y). You are also given an array pathCoordinates [ ] where each element is a (a,b) pair. 
The ith pair (a,b), in the array, denotes that in the ith move you moved your X co-ordinate by a and Y co-ordinate by b. 
if X,Y coordinates in an instant are (c,d) then your next move will be to ( c+a, d+b). 
Example 1:
Input: x = 2, y = 2, 
pathCoordinates = {{1,0},{0,1},{1,1}}
Output: {0,0}
Explaination:
{0,0} was the starting point of the traveler.
At first he changed his X co-ordinate by 1 and
Y co-ordinate by 0.
{0,0} -> {1,0}
After that he changed his X co-ordinate by 0 and
Y co-ordinate by 1.
{0,0} -> {1,0} -> {1,1}
And finally, he changed his X co-ordinate by 1 and
Y co-ordinate by 1.
{0,0} -> {1,0} -> {1,1} -> {2,2}



Example 2:
Input: x = 1, y = 2,
pathCoordinates = {{1,1}}
Output: {0,1}
Explaination:
The route followed by the traveller is
{0,1} -> {1,2}.

 
Your Task:
You don't need to read or print anything. Your task is to complete the function findStartingPoint() which takes x, y, and pathCoordinates as input parameters and returns a list containing the starting point.
 
Expected Time Compelxity: O(n) where n = length of pathCoordinates.
Expected Space Complexity: O(1)
 
Constraints:
1 <= n <= 103
+1
pratikkumarinternAdmin5 months ago
Hi everyone,
We've updated the problem statement.
0
MD MAHDOOD AHMAD1 year ago
MD MAHDOOD AHMAD
vector<int> findStartingPoint(int x, int y, vector<vector<int>>P){    vector<int> v;    for(int i=0;i<p.size();i++){ x="x-P[i][0];" y="y-P[i][1];" }="" v.push_back(x);="" v.push_back(y);="" return="" v;="" }<="" b="">
0
aakash jaiswal1 year ago
aakash jaiswal
#include <stdio.h>
int main() {//codeint t;scanf("%d",&t);while(t--){    int x,y,n,arr[500],sum1 = 0,sum2 = 0;    scanf("%d %d",&x,&y);    scanf("%d",&n);    for(int i = 0 ; i < 2*n ; i++)    {        scanf("%d",&arr[i]);    }    for(int i = 0 ; i < 2*n ; i++)    {        (i % 2 == 0) ? (sum1 += arr[i]) : (sum2 += arr[i]);    }    printf("%d %d\n",x-sum1,y-sum2);}return 0;}
0
Prateek Somani2 years ago
Prateek Somani
Simple Iterative code#include <iostream>using namespace std;int main() {    int t;    cin>>t;    while(t--){        int x,y,n,a,b;        cin>>x>>y;        cin>>n;        for(int i=0;i<2*n;i=i+2){            cin>>a;            x = x-a;            cin>>b;            y = y-b;        }        cout<<x<<" "<<y<<"\n";="" }="" return="" 0;="" }<="" code="">
0
Manish Kumar2 years ago
Manish Kumar
.02 se
#code#for finding starting point ,travellera=int(input())for i in range(0,a):    x,y=list(map(int,input().split()))    c=int(input())    d=list(map(int,input().split()))    e=sum(d[0::2]) # For doing summ of d[0]+d[2]+..,Remember this away    f=sum(d[1::2])  # For doing summ of d[1]+d[3]+..    g=x-e    h=y-f
    print(g,h)
0
Drigger2 years ago
Drigger
Sol in c: https://ide.geeksforgeeks.o...ET: 0.01Array has been used. :)
0
Pratik Goutam
This comment was deleted.
0
Yash Khatri2 years ago
Yash Khatri
simplest sol.(0.15)https://ide.geeksforgeeks.o...
0
Pradip Basak3 years ago
Pradip Basak
There could be no more pathetic explanation to a problem than this.
0
Harsh Tyagi3 years ago
Harsh Tyagi
for _ in range(int(input())) :        x,y=(int(i) for i in input().split())        n = int(input())        arr = list(map(int,input().strip().split()))        sum1=sum(arr[0::2])        sum2=sum(arr[1::2])        print(x-sum1,y-sum2)
We strongly recommend solving this problem on your own before viewing its editorial. Do you still
                    want to view the editorial?
 Login to access your submissions. 

Problem


Contest

Reset the IDE using the second button on the top right corner.
Avoid using static/global variables in your code as your code is tested against multiple test cases and these tend to retain their previous values.
Passing the Sample/Custom Test cases does not guarantee the correctness of code. On submission, your code is tested against multiple test cases consisting of all possible corner cases and stress constraints.
You can access the hints to get an idea about what is expected of you as well as the final solution code.
You can view the solutions submitted by other users from the submission tab.