Recent Articles

Print Series - AUTOMATA FIX

1 day ago

Problem - (ID 6463)

You are required to complete the given code by reusing existing functions. You can click on Run anytime to check the compilation/ execution status of the program. You can use printf to debug your code. The submitted code should be logically/syntactically correct and pass all test cases. Do not write the main() function as it is not required.

Code Approach: For this question, you will need to complete the code as in given implementation. We do not expect you to modify the approach.

The function printSeries(int S, int D, int T, char ch) accepts integer S as the starting term of series, integer D as the common difference for AP or common ratio for GP, integer T as the number of terms and a character ch as the series type to print. It is supposed to print the arithmetic progression if the character ch is 'A' and print the geometric progression if the character ch is 'G'.

The program must calculate both arithmetic progression and geometric progression.

However, an incomplete code in the function printSeries does not print the desired output for all the test cases.

You will have to complete the code to make it work so that the program passes all the test case.

Erroneous Code

void printSeries(int S, int D, int T, char ch)
{
    while(T > 0)
    {
        if(ch == 'A')
        {
            S += D;
        }
        else if(ch == 'G')
        {
            S *= D;
        }
        printf("%d ", S);
        T--;
    }
}

Explanation:
The series value is printed from the second term without printing the first term as the printf statement is placed after calculating the next term in the series. So the value S must be printed before calculating the next term in the series.

Solution:

void printSeries(int S, int D, int T, char ch)
{
    while(T > 0)
    {
        printf("%d ", S);
        if(ch == 'A')
        {
            S += D;
        }
        else if(ch == 'G')
        {
            S *= D;
        }
        T--;
    }
}

 

View

Same Positions Bit Count - AUTOMATA FIX

1 day ago

Problem - (ID 6439)

You are required to fix all logical errors in the given code. You can click on Run anytime to check the compilation/execution status of the program. You can use printf to debug your code. The submitted code should be logically/syntactically correct and pass all test cases. Do not write the main() function as it is not required.

Code Approach: For this question, you will need to correct the given implementation. We do not expect you to modify the approach or incorporate any additional library methods.

The function samePositionBitCount(int N1, int N2) accepts two integers N1 and N2 as the input. The function is supposed to return the count of bits which are equal in both the integers at the same positions.

The function compiles fine but fails to return the desired result due to logical errors.

Your task is to fix the program so that it passes all test cases.

Erroneous Code:

int samePositionBitCount(int N1, int N2)
{
    int count = 0;
    int N3 = N1 ^ N2;
    int max = N1 > N2 ? N1 : N2;
    while(N3 > 0)
    {
        if((N3 & 1) == 0)
        {
            count++;
        }
        max /= 2;
        N3 /= 2;
    }
    return count;
}

Explanation:

Let 12 and 8 be the values of N1 and N2. So the value of N3 is N1 XOR N2 as given below,

1100 = 12 -> N1
1000 = 8  -> N2
----------
0100 = 4  -> N3

The count of zeroes in N3 gives the count of bits which are equal in the same positions.
The loop must run to check all the bits in N3 even if the leftmost bit in N3 (0100) is 0.
So the correct condition in the while loop must be,

while(max > 0)

Solution:

int samePositionBitCount(int N1, int N2)
{
    int count = 0;
    int N3 = N1 ^ N2;
    int max = N1 > N2 ? N1 : N2;
    while(max > 0)
    {
        if((N3 & 1) == 0)
        {
            count++;
        }
        max /= 2;
        N3 /= 2;
    }
    return count;
}

 

View

COGNIZANT CTS AMCAT AUTOMATA FIX PROGRAMMING Latest Questions

2 weeks ago

COGNIZANT CTS AUTOMATA FIX PROGRAMMING QUESTIONS based on LATEST Drives

Error Correction Example Program:

Program 1) Fix Compilation Errors in multiplyNum function https://youtu.be/F7RRpBzcvLg
Program 2) countElements https://youtu.be/P_DJp7f1Qq4
Program 3) calculateSumOfOddElementsInMatrix https://youtu.be/4vD537GIZmI
Program 4) CTS Automata Fix Problem - Find Minimum Element https://youtu.be/OJB7Hbqwmkw
Program 5) CTS AUTOMATA FIX : drawPrintPattern with 1s  https://youtu.be/1HF-X-largg
Program 6) CTS AUTOMATA FIX : oddElements in Array in a new Array https://youtu.be/TeYFwWX_jjc
Program 7) CTS AUTOMATA FIX : removeElement in Array https://youtu.be/LcR5uJeEdzA
Program 8) Print sum of digits of elements in an Array https://youtu.be/eVn_Ldv6Hmw
Program 9) Printing 1 Pattern based on N in an Array https://youtu.be/z8-_c0cB-9Y
Program 10) getArraySum Logical Error https://youtu.be/njJfwPbneI0
Program 11) getPower negative values of Y https://youtu.be/IX_QRso7pzk
Program 12) manchester bits https://youtu.be/093XWG2o1eg
Program 13) character pattern printing https://youtu.be/9pL25oAuJlA
Program 14) Number Modulo Digits Count https://youtu.be/RWmxapZmW5g

 

View

Cognizant CTS LATEST TEST PATTERN for CAMPUS HIRING 2018-2019 Graduation Batch

2 weeks ago

Cognizant - CTS has revised it's campus hiring placement screening test pattern with the following sections.
1. Quantitative Aptitude (16 Questions - 16 Minutes)
2. Logical and Analytical Reasoning (24 Questions - 35 Minutes)
3. Verbal (22 Questions - 18 Minutes) (Includes Reading Comprehension)
4. AUTOMATA FIX (7 Questions - 20 Minutes) - NEWLY ADDED SECTION for 2019 Graduation Batch CAMPUS HIRING

Section 4: Automata Fix Coding
Cognizant has introduced a new coding module called AUTOMATA FIX in it's campus hiring screening test pattern.
The test will be delivered by Aspiring Minds (AMCAT). 5 questions will be of Error Rectification type and the remaining 2 questions will be of FIll in the Code (Using existing functions and completing the implementation logic type)

The following question types are available in AUTOMATA FIX.

Logical: The candidate is required to fix all logical errors in the given code. This checks the various logical concepts like conditions, looping etc.

Example Program 1: http://skillrack.com/solve/6426

Program 1) Fix Compilation Errors in multiplyNum function https://youtu.be/F7RRpBzcvLg
Program 2) countElements https://youtu.be/P_DJp7f1Qq4
Program 3) calculateSumOfOddElementsInMatrix https://youtu.be/4vD537GIZmI
Program 4) CTS Automata Fix Problem - Find Minimum Element https://youtu.be/OJB7Hbqwmkw
Program 5) CTS AUTOMATA FIX : drawPrintPattern with 1s  https://youtu.be/1HF-X-largg
Program 6) CTS AUTOMATA FIX : oddElements in Array in a new Array https://youtu.be/TeYFwWX_jjc
Program 7) CTS AUTOMATA FIX : removeElement in Array https://youtu.be/LcR5uJeEdzA
Program 8) Print sum of digits of elements in an Array https://youtu.be/eVn_Ldv6Hmw
Program 9) Printing 1 Pattern based on N in an Array https://youtu.be/z8-_c0cB-9Y
Program 10) getArraySum Logical Error https://youtu.be/njJfwPbneI0
Program 11) getPower negative values of Y https://youtu.be/IX_QRso7pzk
Program 12) manchester bits https://youtu.be/093XWG2o1eg
Program 13) character pattern printing https://youtu.be/9pL25oAuJlA
Program 14) Number Modulo Digits Count https://youtu.be/RWmxapZmW5g

Compilation:  Candidate needs to correct the syntax of the given code without changing it's logic.  This checks the candidate basic knowledge of syntax and language specific concepts.

Code reuse:  Candidate needs to complete the given code by reusing existing functions. This is a bit tougher than the logical and compilation based questions. The candidate is required to complete the code using the predefined structure or functions.

 

View

TCS NINJA Test Pattern 2018-2019 Batch

1 month ago

TCS Ninja test pattern for 2019 Batch students to be conducted in September 2018

MCQ - Section 1:
Session 1: Contains 20 questions related to Quantitative Aptitude, Reasoning (Duration 40 minutes). (This session will not be there for students who have got 75% in 10th, 12th and in their college. This is applicable only students from accredited colleges)
Session 2: Contains 10 questions related to English Verbal Reasoning and Proficiency (Duration 10 minutes).
Session 3: Contains 10 questions related to C programming proficiency (Duration 20 minutes)

Programming - Section 2:
Contains 1 Programming Challenge to be solved in 20 minutes.

LOG into www.SkillRack.com to take TCS NInja tests.

View

Reverse a String in Java

4 months ago

In this program we will reverse an input String and print the reversed String.

We will use StringBuilder to achieve the reversal.

import java.util.Scanner;

public class Hello {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String input = sc.nextLine();
        
        //We will reverse the String using StringBuilder.
        StringBuilder sb=new StringBuilder(input);
       
        //Now reverse the input value and print 
        System.out.println(sb.reverse().toString());
       
    }
}

 

View

Program to print Fibonacci series in Java

4 months ago

In this article we will look at a Java program that will print Fibonacci series upto a certain number of terms using recursion.

The number of terms is passed as input.

import java.util.Scanner;

public class Hello {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int termsCount = sc.nextInt();
        int sum = 1, curr = 1;
        System.out.println(curr);
        fibonacci(curr, sum, termsCount);
    }

    private static void fibonacci(int curr, int sum, int remainingTerms) {
        if (remainingTerms != 1) {
            System.out.print(sum);
            fibonacci(sum, curr + sum, remainingTerms - 1);
        }
    }
}

 

View

INFOSYS Test Pattern 2019 Batch - LATEST

4 months ago

INFOSYS TEST Pattern (The campus hiring online test pattern has not been changed from 2015 Batch and is still the same for 2018 - 2019 graduation batch):

Test Duration: 95 minutes
Total Questions: 65

3 Sections:

  1. Quantitative : 10 questions in 35 minutes
  2. Logical/Analytical Reasoning : 15 questions in 25 minutes
  3. Verbal :  40 questions in 35 minutes.

But Infosys changes the question by preparing different question sets for each event. So while you will get the similar pattern of questions, it is difficult to get the exact questions repeated.

 

View