Manhattan associates Interview Question for Developer Program Engineers


Country: India
Interview Type: In-Person




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

public int count(int num) {
		int count = 0;

		while ((num / 10) > 0) {
			num = num / 10;
			count++;
		}
		return count + 1;

}

- Avinash December 04, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Seems to be correct for positive numbers. You haven't taken negatives into account, though. No one said the int's unsigned...

- eugene.yarovoi December 05, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Seems it is possible for integers only

- Rani December 26, 2011 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Won't be the fastest variant, but the easiest for me :-)

int count(int num){
char tmp[20];
snprintf(tmp, sizeof(tmp), "%d", num);
return strlen(tmp);
}

- JeffJ January 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

According to C99 standard there's no need of the tmp variable, just call snprintf with a NULL pointer and size=0:

return snprintf(NULL, 0, "%d", num);

This is not portable to SUSv2, tough.

- david.rebatto@gmail.com March 30, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 2 vote

<pre lang="" line="1" title="CodeMonkey34461" class="run-this">int count(int N)
{
int lenOfN = 0;
while(N > 0)
{
lenOfN++;
N = N / 10;
}
return lenOfN;
}
</pre><pre title="CodeMonkey34461" input="yes">
</pre>

- Anonymous December 03, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I see some bugs. What if N = 0? Shouldn't the answer be 1? What if the number's negative?

- eugene.yarovoi December 05, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

You can use Log base 10 then add 1
Examples:
log 11 = 1.04139269 + 1 = 2 digits
log 123 = 2.08990511 + 1= 3 digits
log 1000 = 3 + 1 = 4 digits

- HopeIFindAJob December 08, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote
try this {{{ int count (int num) { int base = 100000; int count = 6 do{ temp = num/base; if (temp==0) { base/=10; count--; continue; } if (temp !=0) { if (temp/10) { base*=10; count++;continue;} else { return count;} } } - Varun January 11, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int count(int num)
{
static int i=1;
while(num)
{
num=num/10;
if(num)
i++;
}
return i;
}

- Anonymous January 19, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int count(int num)
{
static int i=1;
while(num)
{
num=num/10;
if(num)
i++;
}
return i;
}

- Anonymous January 19, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int count(int num)
{
static int i=1;
while(num)
{
num=num/10;
if(num)
i++;
}
return i;
}

- Rahul Mahindru January 19, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int count(int num)
{
    int c = 1; 
    while((num/=10) || (num%10)) c++;  
    return c;
}

- Arijit January 31, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

we can use string function, but it works only on integer values and positive values.. if u want to work on negative, ignore - sign before assigning to string, or float/double values ignore value after dot.

public static void main(String[] args) {
		String number="200";
		System.out.println("number of characters in the number is: "+number.length());

}

- Dhanalakshmi November 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class JavaApplication1 {

    
    public static void main(String[] args) {
      int number=1233, count=1;
      while(number/10!=0){
          number=number/10;
          count=count+1;
      }
      
      System.out.println(count);
    }
}

- sonali gupta August 08, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class JavaApplication1 {

    
    public static void main(String[] args) {
      int number=1233, count=1;
      while(number/10!=0){
          number=number/10;
          count=count+1;
      }
      
      System.out.println(count);
    }
}

- sonaligupta847 August 08, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Int I = 10;

For (I = 6; I >= 3; Iā€”)
{
Printf(ā€œ%dā€, I);
}

- Anonymous November 02, 2021 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

for(let i=0;i<100;)console.log((++i%3?'':'fizz')+(i%5?'':'buzz')||i)

- Anonymous March 22, 2022 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

I will use the modulo and divide operands to store the remainder and the quotient and count the characters in a number. I am assuming the question is to find no.of characters in a number like 4328.

int count ( int num)
{
   int n = 0;
   int rem = num % 10;

   while (rem != 0)
   {
       n = n + 1;
       num = num / 10;
       rem = num % 10;
   }
   return n;
}

- Anonymous December 03, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

it seems it doesn't work for num==0
count(0) == 1

- Anonymous December 03, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

int CountLength( int num)
{

int count = 0;

if ( num == 0)
return 1;


While ( num / 10 ! = 0 )
{

count ++;
num = num/10;
}

return count;

}

- Raj January 11, 2012 | Flag


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