Ayush7614 / Daily-Coding-DS-ALGO-Practice

A open source project🚀 for bringing all interview💥💥 and competative📘 programming💥💥 question under one repo📐📐
https://daily-ds-algo.github.io/DS-Algo-Website/
MIT License
320 stars 476 forks source link

Left Or Right #1886

Open KushagraJain58-cmd opened 3 years ago

KushagraJain58-cmd commented 3 years ago

Aim

Want to add a solution of "Left Or Right" Kindly assign me this problem. I would like to add my solution to this problem in C++ easily and efficiently using multi-dimensional array. Link to the problem: https://www.hackerearth.com/practice/data-structures/arrays/multi-dimensional/practice-problems/algorithm/left-or-right-92c0b54c/

Details

A country X consists of N cities numbered 0 through N−1. The map of this country can be represented as a cycle — for each valid i, city i has exactly two neighboring cities (i+1)%N and (i−1+N)%N.

The cities in the country are broadly categorized into different types. For each valid i, the type of city i is denoted by Ai.

A person called Suarez wants to travel between some pairs of the cities. You are given Q queries. In each query, Suarez wants to travel from city number Y to a city of type Z. Also, he wants to travel only in a given direction along the cycle.

The direction is represented by a letter — L or R. If it's L, Suarez may only move from city i to city (i−1+N)%N for each valid i. If it's R, he may only move from city i to city (i+1)%N.

You need to find the minimum number of steps Suarez needs to take to reach a city of type Z if he starts moving from city Y in the given direction (he can take zero steps). In one step, Suarez can move from his current city to a neighboring city.

If Suarez can never reach a city of type Z for a given query, print 1 instead.

Programming language

KushagraJain58-cmd commented 3 years ago

Kindly assign me this issue under LGM-SOC'21 @ravikr126

KushagraJain58-cmd commented 3 years ago

Please assign me this issue under LGM-SOC'21 @ravikr126