Min Steps in Infinite Grid Solution Program [InterviewBit Question]

Minimum Steps in Infinite Grid.

This programming question is often asked in many It Giants Interview questions and competitive programming Questions. Often Google and Amazon asked in their Software Engineering interview.

The same programming question you can also find on the InterviewBit: Coding Interview Question.

In this post, we are going to solve the problem in Java. You can also solve the Minimum steps to reach the destination in your choice of programming language.

You might like this also: Find Duplicate In Array (Java)- InterviewBit Problem Solution

Problem Statement of Minimum Steps in Infinite Grid Competitive Programming Question

You are in an infinite 2D grid where you can move in any of the 8 directions:

(x,y) to
(x+1, y),
(x – 1, y),
(x, y+1),
(x, y-1),
(x-1, y-1),
(x+1,y+1),
(x-1,y+1),
(x+1,y-1)

You are given a sequence of points and the order in which you need to cover the points. Give the minimum number of steps in which you can achieve it. You start from the first point.

Example :

Input : [(0, 0), (1, 1), (1, 2)]
Output: 2

It takes 1 step to move from (0, 0) to (1, 1). It takes one more step to move from (1, 1) to (1, 2).

How to Print Colored Text Console Output in Java

Java Source Code of Minimum Steps in Infinite Grid


You can also get more competition programming question solution on here.

You can also get latest coding problems and many more code snippets directly to your Email by subscribing our newsletters.

You Might Like This

Linked List Data Structure Program In Java

How to Create 2D Matrix Using ArrayList Collection Class In Java

Find Duplicate In Array (Java)- InterviewBit Problem Solution

Find Duplicate Number In Array [Java Program].

This is the competitive programming question which is asked in many competitive programming practice websites, in an interview with the Google, Amazon-like MNCs, etc.

You can also find the same problem definition on the InterviewBit: Coding Interview Question.

Problem Definition of Competitive Programing Interview Question Find Duplicate Number In Array

You Might Like this also: How to Create 2D Matrix Using ArrayList Collection Class In Java

Given a read-only array of n + 1 integers between 1 and n, find one number that repeats in linear time using less than O(n) space and traversing the stream sequentially O(1) times.

Sample Input:

[3 4 1 4 1]

Sample Output:

1

If there are multiple possible answers ( like in the sample case above ), output any one.

If there is no duplicate, output -1

 Java Source Code of Find Duplicate In Array

So this is the source code of the Find Duplicate Number In Array. The program is implemented in the Java. You can also code the solution of the same problem in any programming language of your choice.

You will also get the Solution of programming interview question of various Companies Like Amazon, Microsoft, TCS, Yahoo, Google on the Code Puran.

You Might Like this also: How to Print Colored Text Console Output in Java

If you like this Article and want more code snippets like this, best programming practices then you can follow us on the social media site, or you can also subscribe to our new letters to brush up your programming skill.