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),

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:


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.

Best CSS3 Animation Demo [Super Mario Animation In HTML CSS]

CSS3 Animation Example. You can create the simple to more complex Animations in using the HTML and CSS. Yes, CSS is now just limited to traditional style sheet script. You can much more do with the CSS and get the design attractive website and UX.

In this post, we are going to show one of such CSS3 Animation example cum Demo to learn how we can implement the CSS3 Animation.


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

Here is the code Snippet of the CSS3 Mario Animation Example





Brief Explanation of the code of CSS3 Animation Example

In CSS3 Animation the main property which plays the role to generate the Animation is the @keyframes rule and the animation ownership of the CSS.

@keyframes has specified the Animation code, and it will change the style parameter value at the particular point of time.

To know more about @keyframes and CSS animation property and complete CSS Animation tutorial you can visit the www.w3Schools.com.

Source Code Credit

The Source Code of this post is originally written by my classmate and the friend Qaidjohar and also published on his blog:  techcontributors.blogspot.in.

Posts You May Like

Java Code to Send E-mail using Gmail SMTP Server

Linked List Data Structure Program In Java

Java Code to Send E-mail using Gmail SMTP Server

This is the simple program that uses the Java Mail API to send the email from the Java code using the SMTP server of the Gmail.

In this simple program, we are going to use the Java Mail API by Oracle. You can download the Java Mail API Jar files directly from the links given below, or you can also download from the official site.

Where can you use this code snippet?

If in your application you ever need to send the email to the user for confirmation of registration, password reset links and any email then this simple program is very handy for you.

If you don’t want to setup your mail server and want to send the email to your user or for testing purpose or want to set up things quickly, then you can use the SMTP server of the email.

I used this program to send an email via Gmail server in my college project for password reset, confirmation, email notification.

Source Code of Sending Mail in Java via Gmail SMTP server

While running this program you can hit by the AuthenticationFailedException. To resolve this exception you have to Turn on Access to less secure apps in Google account settings.

You can find this setting page on this link:


In this page Turn On the Feature then you can send the Email through your Java code via Gmail.

If you like this program and want to know about more programming code snippets then you can also subscribe to our new letter.

Linked List Data structure Program In Java

Here is the simple program of implementation of the fundamental data structure Linked List in Java.

The program contains the basic Linked List Operation Display List and the Insert Node in the Linked List.

However, as the permits me I will update this program and add the other Operation in the code snippet.

If you want to use a LinkedList data structure in your program, then you can use the Java SE Standard Library API collection in your Java Program. By using the Collection class, you will get the number of the basic Linked List Operations.

You can use this program to understand the concept of implementation of the Linked List data structure in the Java.

Source Code



If you find this program useful, then you can share this program on social media platforms, and you can also subscribe to our New Letters to Find the more code snippet like this.

You also can comment your review about the program in the comment box below.

How to Print Colored Text Console Output in Java

While programming in Java sometimes you may need to print the output of the program in the console to testing and debugging the program. While program throws many exceptions and prints tens of lines in the console, you may find it difficult to find the actual exception message.

In this case, it is good practice to change the color of the particular exception message so that we can easily debug the program and it will make our work easier.

There is another need to modify the output color of text while you are writing the command line application. It is a good Idea to change the color of the particular output line to highlight the main point of the output.

I find this trick useful while programming such type of command line tool and the debugging the web and desktop application.

You can also use this tricks to change the console output color using system.out.print() function in Java.

However this DOS / Window doesn’t support the ANSI colored character so that you won’t be able to run this program correctly in the Windows Command Prompt. You can use the console of the IDE like Eclipse, NetBeans etc and the any Linux distro terminal.

Change Output Text Color In Java

Source Code