Thursday 25 June 2015

Urban Ladder Coding Challange Sample Questions Asked on 26th June 2015

Q1)FizzBuzz
---------------------------------------------------------------------------------

Write a program that prints the numbers in the given range. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”. Print a new line after each string or number.
Input Format First line will be the number of testcases, T. Next line will have T integers, denoted by N.
Output Format For each testcase, print the number from 1 to N. But follow the rules given in the problem statement.
Constraints
1 <= T <= 10
N is an integer.
Please read the below instructions carefully
  1. You can choose any language from the given list to write your solution.
  2. All input to the programming solution is to STDIN and output is to STDOUT.
  3. You don't have to manually give the input to your program, just take the input from STDIN and the code evaluation engine will provide the input to your program.
  4. For example if you are coding in C, and the first input is an integer then simply do scanf('%d', &i) assuming you are reading that integer to a variable named i. Similarly if you are using C++ simply do cin >> i
  5. There are two different type of test cases. First type is the sample input and output for which you know both the input and output. You can look at them under the problem statement.
  6. When you click Compile and Test the code will be compiled and tested only on the sample input that is shown to you. Compile and Test is for you to understand if you solution is compiling and running against the sample input. 5 When you click submit, your code will be judged on multiple test cases which are hidden. These tests are not available for you to see them so you will not know the input on which your code will be tested. But it is assured that all inputs will be in the given constraint limit and in the given format as stated in the problem statement.
  7. In order for your code to get accepted, it must clear all the judge test cases. In cases where partial marking is allowed, you will awarded partial marks for the number of test cases your solution passes.
  8. Please note that getting green mark when you hit 'Compile and Test' does not indicate anything on the correctness of your program. It just indicates that your code correctly compiled and ran successfully against the sample input. It can still fail for other test inputs that visible to you.
  9. Do not output anything, except what it is asked for in the output section. Note that you have to output only in the way that is mentioned. Any extra strings in the output will be treated as wrong answer. Even an extra space can lead to the answer not being accepted.
  10. Don't assume any constraints on the input based on the sample input that you see, the actual test cases will be much larger in size. But they will always be within the constraints mentioned in the problem.
  11. To understand how the code is evaluated visit the judge page. There is also a sample code in each language there.
To further understand how the judge works, look at one of the actual test input file and the corresponding expected output for this problem


Sample Input                Sample Output   

2
3 15               1
                   2
                   Fizz
                   1
                   2
                   Fizz
                   4
                   Buzz
                   Fizz
                   7
                   8
                   Fizz
                   Buzz
                   11
                   Fizz
                   13
                   14
                   FizzBuzz



Answer
---------------------------------------------------------------------------------

import java.io.BufferedReader;
import java.io.InputStreamReader;


class TestClass {
    public static void main(String args[] ) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int N = Integer.parseInt(line);
        line=br.readLine();
        String str[]=new String[N];
        int arr[]=new int[N];
        str=line.split(" ");
        for(int l=0;l<str.length;l++){
        arr[l]=Integer.parseInt(str[l]);
        }
        int l=0;
        
        for (int i = 0; i < N; i++) {        
        for(int k=1;k<=arr[l];k++){  
            if(k%3==0 && k%5==0){
        System.out.println("FizzBuzz");
            }else if(k%3==0){
        System.out.println("Fizz");
        }else if(k%5==0){
        System.out.println("Buzz");
        }else{
        System.out.println(k);
        }
       
        }
        l++;
            
        }


       
    }
}



Q2)Sum of Two Numbers
---------------------------------------------------------------------------------

You are given two numbers a and b. Your task is to find the sum of two numbers.
Input
The first line contains an integer t, denoting the number of test cases. Next t lines contain two integers, a and b separated by a space.
Input Constraint
1 <= t <= 1000000000
1 <= a, b <= 1000000000
Output
For every number a and b, output the sum of two numbers a and b.


Sample Input                Sample Output

1
1 2                3




Answer
---------------------------------------------------------------------------------

import java.math.BigInteger; 
import java.io.BufferedReader;
import java.io.InputStreamReader;

class TestClass {
    public static void main(String args[] ) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int N = Integer.parseInt(line);
        for (int i = 0; i < N; i++) {
         line=br.readLine();
         String str[]=new String[line.length()];
      str=line.split(" ");
         BigInteger a=new BigInteger(str[0]);
   BigInteger b=new BigInteger(str[1]);
   BigInteger c=new BigInteger("0");
   c=b.add(a);
   System.out.println(c);
        }
    }
}




4 comments:

  1. Can anyone explain first 5-10 lines of code

    ReplyDelete
  2. i am glad to discover this page : i have to thank you for the time i spent on this especially great reading !! i really liked each part and also bookmarked you for new information on your site.
    QA Companies
    Automation Testing Companies
    Mobile App Testing Companies
    Performance Testing Companies
    Security Testing Companies

    ReplyDelete