Nutanix Interview Question for Software Developers


Country: United States
Interview Type: Phone Interview




Comment hidden because of low score. Click to expand.
2
of 2 vote

ackage com.cracking.nutanix;

public class BuildPyramid {

	public static void main(String[] args) {
		System.out.println( String.format("Input: %d, Possible: %s", 4,isPyramidPossible(4)) );
		System.out.println( String.format("Input: %d, Possible: %s", 9,isPyramidPossible(9)) );
		System.out.println( String.format("Input: %d, Possible: %s", 6,isPyramidPossible(6)) );
	}
	
	public static boolean isPyramidPossible(int bricks) {
		int rowBricks = 1;
		while(bricks > 0) {
			bricks -= rowBricks;
			rowBricks += 2;
		}
		
		return bricks == 0;
	}

}

Output:
Input: 4, Possible: true
Input: 9, Possible: true
Input: 6, Possible: false

- ProTechMulti October 19, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

boolean check(int n)
long squareRoot = Math.round(Math.sqrt(n));
if ((n>0) && (n== squareRoot*squareRoot))
return true;
return false;

- Anonymous October 19, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Analysis.
The problem is that of :
1 + 3 + 5 + ...
That is sum of n odd numbers.
That is known to be : 9math.com/book/sum-first-n-odd-natural-numbers
=> n^2.
Thus we are to find, if the number given is a perfectly square no. or not.
Now, given we do not want to use square root, which is
a terribly complex operation, we can do as follows:
[ careercup.com/question?id=14797683 ]

- NoOne October 19, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

The pattern is 1, 3, 5, 7,.... 2n-1

Sum of numbers from 1 to 2n-1 = 1/2 n(1 + 2n-1) = n^2.

So, given a number, check if its root is a perfect integer.

return (int)Math.sqrt(n) * (int)Math.sqrt(n) == n;

- S October 25, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

"""
To make a pyramid
the first row will have 1 *
the second row will have 3 *
the third row will have 5 *
the N th row will have 1+3+5+7. (expand sequence to have N terms )

The sum or first n odd numbers is n*n
For forming a pyramid with N *s - N should be a perfect square
"""
import math
def isPyramidPossible (n):
    root = int (math.sqrt(n))
    return int (root)  == n //root


def main(n):
    print (f'A pyramid with {n} *s is {"" if isPyramidPossible(n) else "not"} possibe')

if (__name__== "__main__"):
    for i in range (1, 100):
        main (i)

- Makarand October 22, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Simple Python Solution

def pyramid(a):
  num = 1
  new_num = 0
  while new_num != a and new_num <= a:
    
    new_num = num + new_num
    num += 2
    print("new num is: ", new_num)
  if new_num == a:
    return True
  return False

- shahvansh123 October 28, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This will be the pattern 1,4,9,16,25,36,..
if n is a perfect square , we can build the pyramid otherwise not .

- Anonymous February 22, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

since first row will have 1 star 2nd row 3 star 3rd row 5 star so on.
so to make n row you should have total star equal to sum of first n odd numbers.
As you can see above first n odd number form Arithematic progression with difference of 2
sum of n numbers of an Arithematic progression =(n* (2*a+(n-1)*d))/2
where n = number of term
a(first term) = 1
d(difference) = 2
so sum = (n*(2*1+(n-1)*2)/2 = n*n = n^2
so you simply have to check number of star is perfect square or not.

- amit.99531 October 23, 2018 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More