Sunteți pe pagina 1din 29

1.

QUESTION [100,22,43,912,56,89,85],[234,123,450,234,890,101]
Public class charecterpattern{ Expected return value:
Public static void printcharecterpattern ( int num){ 912
Int i , j,value = 1; 3.QUESTION
Char ch = „a‟; The function findMaxElement(int *arr1,int len1,int
Char print = ch; *arr2,int len2) accepts two integer arrays arr1,arr2 of
For(j=0;j<=i;j++) length len1,len2 respectively.
System.out.print( (ch ++ )); It is supposed to return the largest element in both the input
System.out.println( ** ); arrays.
} Another function sortArray(int *arr,int len) sorts the
} input array arr of length len in ascending order and returns
} the sorted array.
1.(1)TESTCASE 1: Your task is to use sortArray(int *arr,int len) function
Input: and complete the code in findMaxElement(int *arr1,int
5 len1,int *arr2,int len2) so that it passes all test cases.
Expected output: PROGRAM
a int *sortArray(int *arr,int *len)
ab {
abc int i=0,j=0,temp=0,index=0;
abcd for(i=0;i<len;i++)
abcde {
testcase 2: for(j=i+1;j<len;j++)
input: {
1 If(arr[i]>arr[j])
Output: {
a temp=arr[i];
2.QUESTION arr[i]=arr[j];
Public class Maxarrayelement arr[j]=temp;
{ }
Public static int[] sortArray{int[] arr} }
{ }
Int i=0,j=0,temp=0,index=0; return arr;
For(i=0;i<arr.length;i++) }
{
For(j=i+1;j<arr.length;j++) 4.QUESTION
{ The methods GetDigitSum(int arr[]) of
If((arr[i]>arr[j]) class DigitSum accepts an integers array arr it is supposed
{ to calculate the sum of digits of the even of the smallest
Temp = arr[i]; elements in the input array it returns 1 if the calculated sum
Arr[i] = arr[j]; is even and returns 0 otherwise
Arr[j] = temp; However there is a compliation error in the code your task
} is to fix it so that the program works for all the input values
} PROGRAM
} Public class Digitsum
Return arr; {
} Public static int getDigitSum(int arr[i])
Public static int findMaxElement(int arr1[],int arr2[]) {
{ Int result,len=arr.length;
Return arr1[]; For(int i=0;min=arr[0];i<len;i++)
} {
TESTCASE 1 if(arr[i]<min)
Input: min=arr[i];
[2,5,1,3,9,8,4,6,5,2,3,11],[11,13,2,4,15,17,67,44,2,100,23] }
Expected return value: results=getSum(min)
100 if(results%2==0)
Input: return 1;
else count++;
min==arr[j]; }
} return count;
} }
} }
5.PROGRAM 8.QUESTION
Public class Datecomparer The method countElement(int arr[],int n) of class
{ ElementCount is supposed to return the number of elements
Public static int different_in_dates(Date date1,Date date2) in the input array arr which are greater than twice the input
{ number n
Return 0; PROGRAM
} Public class ElementCount
} {
5.1 TESTCASE 1: Public static int countElement(int arr[], int n)
Input: {
2/5/2013,2/6/2013 Int I,cou-nt=0, len=arr.length;
Expected Return value For(i=0,i<len,i++)
31 {
Input: If(arr[i]>2n)
1/6/2012,1/6/2011 Cou-nt—1;
Expected Return value }
366 Return cou.nt;
6.QUESTION }
The Function arrayReverse(int *arr,int len) accepts an }
array arr of length len(len >=0) as an argument.The 9.QUESTION
function is expected to reverse the elements of the input The method reversearray(int arr[]) of class sortarray
array in-place. accepts an input array arr as an arguments.This function is
For example, if the input array arr is {20,30,10,40,50} the expected to reverse the elements of the array in-place
function is expected to return{50,40,10,30,20} PROGRAM
The function compiles successfully but fails to return the int arrayReverse(int *arr,int len){
desired result due to logical errors int i,temp,originallen=len;
PROGRAM: for(i=0;i<=i<=originallen/2;i++){
int arrayReverse(int *arr,int len){ temp=arr[len-1];
int i,temp,originallen=len; arr[len-1]=arr[i];
for(i=0;i<=i<=originallen/2;i++){ arr[i]=temp;
temp=arr[len-1]; len-=1;
arr[len-1]=arr[i]; }
arr[i]=temp; Return arr;
len-=1; }
} 10.QUESTION
Return arr; Public class charecterpattern{
} Public static void printcharecterpattern ( int num){
7.QUESTION Int i , j,value = 1;
This method countOccurance (int arr[], int value) of class Char ch = „a‟;
occurrence is supposed to return the count of occurrences Char print = ch;
of a number value in the input array arr. The function For(j=0;j<=i;j++)
compiles successfully but fails to return the desired result System.out.print( (ch ++ ));
due to logical errors. System.out.println( ** );
Your task is to debug the program to pass all test cases. }
PROGRAM }
public class Occurrence{ }
public static int Occurrence (int arr[], int value) 10.(1) TESTCASE 1:
{ Input:
int i=0, count=0, len=arr.length; 5
while(i<len){ Expected output:
if(arr[i]==value) a
ab {
abc if((arr[i]%2==0)&&(arr[i]==arr[i++]))
abcd count++;
abcde }
testcase 2: return count;
input: }
1 }
Output: 14.(1)TESTCASE 1:
a Input:
11.PROGRAM [1,5,5,2,2,7,8,6,6,9,10],11
Int isRighttriangle(point *p1 , point *p2,point *p3) Expected return value:
{ 2
} TESTCASE 2:
11.(1) TESTCASE 1: Input:
Input: [13,12,12,13,14],5
(2,4)(4,2)(1,2) Expected return value:
Expected output 1
0 15.PROGRAM
testcase 2: Public class DateComparer
input: {
(-4,0)(2,0)(-3,-4) Public static int difference_in_dates(Date date1, Date
Output: date2)
1 {
12.QUESTION //write your code
The function Manchester(int *arr,int len)accepts an array return 0;
arr of legth len (len>0) as an input.Each element of an }
represents a bit -0 0\=or 1.The output is an array with the }
following property. 15(1). TestCase 1:
PROGRAM Input:
Int * Manchester(int*arr, int len){ 3, [7,0,1,2,0,3,0,4,2,3,0,3,2,1,2,0], 16
Int* res = (int*)malloc(sizeof(int)*len); Expected Return Value:
For(int i= 0; i< len; i++){ 11
Res[i]= (arr[i]==arr[i-1]); TestCase 2:
} Input:
Return res; 2, [2,3,1,3,2,1,4,3,2], 9
} Expected Return Value:
13.QUESTION 8
Write a method to determine if a given string contains 16.QUESTION
balanced sequence of parenthesis.The input to the method You are given a pre-defined structure primebank and also a
balanceparentheses of class parentheses is a string str.Each collection of related functions which can be used to
character in the string will be “(“ or “)”.The output is the perform some basic operations on the structure
court of balanced pairs if the sequence is balanced or -1 PROGRAM
otherwise Void printprime(int num, int digit)
PROGRAM {
Public class parentheses }
{ 17.PROGRAM
Public static int balancedparentheses(string str) The function patternPrint(int n) supposed to print n
{ numberof lines in the following pattern
For n=4 the pattern should be:
} 1
} 11
14 PROGRAM 111
int sameelementcount(int * arr, int len) 1111
{ The function complies successfully but fails to return the
Int i,count = 0; desired results due to logical errors
For(i=0;i<len-1;i++) Your task is to debug the program to pass all the testcases
Program number of elements in an arr which are even numbers and
Void patternPrint(int n) equal to the element to its right
{ Int sameelementcount(int *arr, int len)
Int print=1,i,j; {
For(int i=0;i<n;i++) int i,count=0;
{ for(i=0;i<len-1;i++)
For(j=0;j<=i;j++) {
{ if((arr[i]%2==0)&&(arr[i]==arr[i++]))
Printf(“%d”,print);} count++;
} }
Print(“\n”); return count;
} }
} 21 PROGRAM
17(1) TESTCASE 1 Int countoccurence(int *arr, int len,int value){
INPUT 1 Int i=0, count = 0;
3 While(i<len){
EXPECTED OUTPUT VALUES If(arr[i]++value)
1 Count += I;
11 }
111 Return count;
INPUT 2 }
1 22.PROGRAM
EXPECTED OUTPUT VALUES public class Median
1 {
18 PROGRAM public static int median(int arr[])
int multiplyNumber(int a, int b, int c) {
{ int start_index=0;
int result, min, max, mid; int len=arr.length;
max=(a>b)?a>c)?a:c): (b>c)?b:c; int end_index=len-1;
min(a<b?((a<c)?a:c): ((b<c)?b:c); int res=-1;
mid=(a+b+c)-(min+max) if(len%2!=0)
result=(max*int mid) {
return result; int median_order=((len+1)/2);
} medianCalculate ob=new
QUESTION medianCalculate(arr,start_index,end_index,median_order);
The function multiplynumber(int a , int b,int c)accepts three res=ob.quick_select();
integers a,b and c as inputs,it is supposed to return the }
multiplication productive of the maximum two or three else
input numbers {
19.QUESTION }
The function Manchester(int *arr,int len)accepts an array return res;
arr of legth len (len>0) as an input.Each element of an }
represents a bit -0 0\=or 1.The output is an array with the }
following property. 22(1). TestCase 1:
PROGRAM Input:
Int * Manchester(int*arr, int len){ [4,2,8,6], 4
Int* res = (int*)malloc(sizeof(int)*len); Expected Return Value:
For(int i= 0; i< len; i++){ [6,8,2,4]
Res[i]= (arr[i]==arr[i-1]); TestCase 2:
} Input:
Return res; [11,20,17], 3
} Expected Return Value:
20.QUESTION [17,20,11]
The function sameelementcount(int *arr,int len)accepts an 23.QUESTION
integer array arr of length len as a input and returns the The method sortarray(int arr[]) of class array accepts an
integer array arr an input and performs an inplace sort
algorithm sort operation on it.the function is expected to res =
return the input array sorted in descending order,but instead (float)quick_select(arr,start_index,end_index,median_order
it returns the value due to bug in the code );
PROGRAM }
Public class MinArray else
{ {
Public static int[] sortArray(int[] arr) }
{ return res;
int i=0,j=0,temp=0,index=0; }
for( i=0;i<arr.length;i++) 25(1) TESTCASE1:
{ Input:
for(j=i+1;j<arr.length;j++) [2,40,23,52,37],5
{ Output
if(arr[i]>arr[j]) 37.000000
{ Input:
temp=arr[i]; [2,12,9,5],4
arr[i]=arr[j]; Output:
arr[j]=temp; 7.000000
} 26.PROGRAM
} Public class arraysum{
} Public static int getarraysum(int arr[1]){
return arr; Int sum = 0;I<len j i* 1}{
} Sum = arr[i];
24.QUESTION }
The function replaceValues(int *arr, int len) accepts an Return sum;
array arr of length len (len>0) as an input and returns an }}
array of the same length. 26(1)TESTCASE
If the length of arr is off, all the elements of arr are Input
supposed to be replaced by 1st and in case it is even, the [2,3,5,7,9]
elements should be replaced by 0s. Output:
PROGRAM: 26
int *replaceValues(int *arr, int len) Input:
{ [-1,-2,-3,-4,-4,-1]
int i,j; Output:
if(len%2==0) -15
{for(i=0;i<len;i+=2) 27.QUESTION
arr[i]=0; The function allexponent(int base,int exponent)accepts two
} integers base and exponent as inputs.it is supposed to
else calculate and return of exponentation of base raised to
{ power exponent for all input values
for(j=0;j<len;j+=2) PROGRAM
arr[j]=1; float allExponent( int base,int exponent )
} {
return arr; float res=1;
} if(exponent >=0)
25.PROGRAM {
float median(int * arr,int len) Res = (float)positiveExponent(base,exponent)
{ }
int start_index=0; Else
int end_index=len-1; {
float res=-1; res=0;
if(len%2!=0) }
{ return res;
int median_order=((len+1)/2); }
28.PROGRAM
int countElement(int arr,int len,int n)
{ White
int i,count=0; Green
for(int i=0;i<len;i++) No color
{ 30 QUESTION
if(arr[i]>(2*n)) The function matrixsum(int **matrix,int m,int n)is
{ supposed to return the sum of elements of the input array
count=+1; matrix having m rows and n columns
} PROGRAM
return count; int calculateMatrixSum(int **matrix, int m, int n)
} {
28. TESTCASE 1: int i,j,sum=0,
Input: for(j=0i<m;j++)
[-2, -4, -3, -5, -6, -7, -8], 7, 3 {
Expected Return Value: For(j=0;j<n;j++)
0 sum+= matrix[i][j];
TESTCASE 2: }
Input: return sum;
[22, 55, 66, 33, 44, 77], 6,13 }
Expected Return Value: 31.QUESTION
5 In order to help her,we have a function checkBirthday(char
29.PROGRAM * month,int day) which takes day and month as inputs and
Public class color returns 1 if is her birthday and returns a.0 otherwise
{ PROGRAM
Public static void printcolor(int num) Int checkBirthday(char* month,int day)
{ {
Switch (num) If(strcmp(month,”july”)||(day-5))
{ Return 1;
Case 1: Else
System.out.println(“Red”); Return 0;
Case 2: }
System.out.println(“Black”); 32.PROGRAM
Case 3: Public class MinArray
System.out.println(“White”); {
Case 4: Public static int[] sortArray(int[] arr)
System.out.println(“Green”); {
default: int i=0,j=0,temp=0,index=0;
System.out.println(“No color”); for( i=0;i<arr.length;i++)
Break; {
} for(j=i+1;j<arr.length;j++)
} {
} if(arr[i]>arr[j])
29(1)TESTCASE 1: {
Status: temp=arr[i];
Wrong arr[i]=arr[j];
Expected: arr[j]=temp;
White }
Returned: }
White }
Green return arr;
No color }
TESTCASE 2: 32(1) TESTCASE 1:
Status: Input:
Wrong [2,5,1,3,9,8,4,6,5,2,3,11],[11,13,2,4,15,17,67,44,2,100,23]
Expected: Output:
White 1
Returned: TESTCASE 2:
Input: The function calculateMatrixSum(int ** matrix, int m, int
[100,22,43,912,56,89,85],[235,123,450,234,890,101] n) accepts a two dimensional array matrix of dimensions m,
Output: n as input and returns the sum of odd elements whose
22 ith and jth index are same.
33.PROGRAM The function compiles line but falls to return the desired
Public class Datecomparer result for some test cases
{ PROGRAM
Public static int different_in_dates(Date date1,Date date2) int calculateMatrixSum(int **matrix, int m, int n)
{ {
Return 0; int i,j,sum=0,row=m, column=n;
} if((row>0)&&(column>0))
} {
33(1) TESTCASE 1: for(i=0;i<row;i++)
Input: {
2/5/2013,2/6/2013 sum=0;
Expected Return value for(j=0;j<column;j++)
31 {
Input: if(i==j)
1/6/2012,1/6/2011 {
Expected Return value if(matrix[i][j]/2!=0)
366 sum+=matrix[i][j];
34 QUESTION }
The method findMinElement(int arr1[i],int arr2[]) of }
class MinArray accepts two integer array }
arr1,arr2 return sum;
it is supposed to return the smallest elements in both the }
input arrays else
Another method sortArray(int arr[]) sorts the input return sum;
array arr in ascending order and returns }
PROGRAM 36.PROGRAM
Public class MinArray Public class Arraysum{
{ Public static int getarraysum(int arr[]){
Public static int[] sortArray(int[] arr) Int sum =0 ;i,len.arr.length;
{ For(i=0;i<len;i=i+1){
int i=0,j=0,temp=0,index=0; Sum =arr[i];
for( i=0;i<arr.length;i++) }
{ Return sum;
for(j=i+1;j<arr.length;j++) }
{ }
if(arr[i]>arr[j]) 36(1)TESTCASE
{ Input:
temp=arr[i]; [2,3,5,7,9]
arr[i]=arr[j]; Expected Return value
arr[j]=temp; 26
} Input:
} [-1,-2,-3,-4,-1]
} Expected Return value
return arr; -15
} 37.QUESTION
public static int findMinElement(int arr[i],int arr2[j]) The function calculate matrixsum(int “matrix ,int m ,int
{ n)accepts a two dimensional array matrix of dimensions m,
return 1; n as input and returns the sum of odd elements whose I and
} l index are same
} PROGRAM
35.QUESTION int calculateMatrixSum(int **matrix, int m, int n)
{
int i,j,sum=0,row=m, column=n; sum+=matrix[i][j];
if((row>0)&&(column>0)) }
{ }
for(i=0;i<row;i++) }
{ return sum;
sum=0; }
for(j=0;j<column;j++) 40.PROGRAM
{ Public class arrayoperation{
if(i==j) Public static int[] replacevalues( int arr[] ) {
{ Int I ,j , len = arr.length;
if(matrix[i][j]/2!=0) If (len % 2==0)
sum+=matrix[i][j]; {
} For(i=0;i==len;i++)
} Arr[i] = 0;
} }
return sum; Else{
} For( j=0;j<=len ;j++)
else Arr[j] = I;
return sum; }
} Return arr;
38.QUESTION }
The method countdigit(int sum) of class digits is supposed }
to return the value remainder when the input arguments 40(1) TESTCASE 1:
num(num>0) is divided by the number of digits in num Input:
PROGRAM [2,5,3,7,9,5]
Public class digits{ Expected Return value
Public static int countDigits ( int num ){ [0,0,0,0,0,0]
Int count =0; Input:
While(num !=0) [21,22,3,24,55]
Num = num / 10; Expected Return value
Count ++; [1,1,1,1,1]
} 41.QUESTION
Return (num % count ); The function findminElement(int * arr1,int len1,int
} *arr2,int len2)accepts two integers arrays arr1,arr2 of
} length len1,len2 respectively
39.QUESTION PROGRAM
The function calculateMatrixSum(int ** matrix, int m, int int *sortArray(int *arr,int *len)
n) accepts a two dimensional array matrix of dimensions m, {
n as input and returns the sum of odd elements whose int i=0,j=0,temp=0,index=0;
ith and jth index are same. for(i=0;i<len;i++)
The function compiles line but falls to return the desired {
result for some test cases. for(j=i+1;j<len;j++)
PROGRAM {
int calculateMatrixSum(int **matrix, int m, int n) If(arr[i]>arr[j])
{ {
int i,j,sum=0,row=m, column=n; temp=arr[i];
if((row>0)&&(column>0)) arr[i]=arr[j];
{ arr[j]=temp;
for(i=0;i<row;i++) }
{ }
sum=0; }
for(j=0;j<column;j++) return arr;
{ }
if(i==j) 42.QUESTION
{ The methods GetDigitSum(int arr[]) of
if(matrix[i][j]/2!=0) class DigitSum accepts an integers array arr it is supposed
to calculate the sum of digits of the even of the smallest You are required to fix all logical errors in the given code.
elements in the input array it returns 1 if the calculated sum You can click on
is even and returns 0 otherwise Compile &amp;amp; Run anytime to check the
However there is a compliation error in the code your task compilation/execution status of the
is to fix it so that the program works for all the input values program. You can use System.out.println to debug your
Note The methods getdigitSum uses another method code. The submitted
getSum(int sum) which returns the sum of the digits of the code should be logically/syntactically correct and pass all
input number num testcases. Do not
PROGRAM write the main() function as it is not required.
Public class Digitsum Code Approach: For this question, you will need to
{ correct the given
Public static int getDigitSum(int arr[i]) implementation. We do not expect you to modify the
{ approach or incorporate
Int result,len=arr.length; any additional library methods.
For(int i=0;min=arr[0];i<len;i++) The method printColor(int num) of the class Color is
{ supposed to print
if(arr[i]<min) names of color according to given input numbers num
min=arr[i]; When the values of num equal 1,2,3,4 the function prints
} “Red”,”Black”,”White”,”Green” respectively for any other
results=getSum(min) values of num it
if(results%2==0) should print “No color”.
return 1; The method complies fine but fails to return the desired
else results for some cases
min==arr[j]; Your task is to fix code so that it passes all the testcases
} PROGRAM:
} Public class color
} {
43.PROGRAM: Public static void printcolor(int num)
public class AllExponent {
{ Switch (num)
public static float allExponent( int base,int exponent ) {
{ Case 1:
float res=1; System.out.println(“Red”);
if(exponent >=0) Case 2:
{ System.out.println(“Black”);
Exponent exp=new Exponent(base,exponent); Case 3:
res = (float)exp.positiveExponent(); System.out.println(“White”);
} Case 4:
else System.out.println(“Green”);
res=0; default:
} System.out.println(“No color”);
return res; Break;
} }
} }
TESTCASE 1: }
Input: 45. QUESTION:
5,2 The function calculateMatrixSum(int matrix[][]) of
Expected Return Value: classMatrixSum accepts a two dimensional array matrix of
25.0 dimensions as input and returns the sum of odd elements
TestCase 2: whose ith and jth index are same.
Input The function compiles line but falls to return the desired
5,-2 result for some test cases.
Expected Return Value: PROGRAM:
0.04 Public class MatrixSum
44. Question : {
Public static int calculateMatrixSum(int matrix[][])
{ implementation We do not expect you to modify the
int i,j,sum=0,row=m, column=n; approach or incorporate
if((row>0)&&(column>0)) any additional library methods.
{ The function sortArray(int * arr,int len) accepts an
for(i=0;i<row;i++) integer array arr of length
{ (len>0) as an input and perform an in place sort operation
sum=0; on it. The function is expected to return the input array
for(j=0;j<column;j++) sorted in descending order
{ The function complies successfully but fails to return the
if(i==j) desired results due to logical errors
{ Your task is to debug the program to pass all the test cases
if(matrix[i][j]/2!=0) PROGRAM:
sum+=matrix[i][j]; int *sortArray(int *arr,int *len)
} {
} int i=0,j=0,temp=0,index=0;
} for(i=0;i<len;i++)
return sum; {
} for(j=i+1;j<len;j++)
else {
return sum; If(arr[i]>arr[j])
} {
46. PROGRAM: temp=arr[i];
Public class Drawpattern{ arr[i]=arr[j];
Public static void printPattern(int n){ arr[j]=temp;
Int i,,j,print = 1; }
For(i=i;i<=n;i++) return arr;
For(j=1;j<=2 * i;j++) }
System.ou.print( (print )); }
System.out.println(); }
} 48. TestCase 1:
} Input:
TESTCASE 1: [1,2,3,4,5,6,7]
Input: Expected Return Value:
4 [7,6,5,4,3,2,1]
Expected Return Value: TestCase 2:
11 Input:
1111 [2,8,4,6]
111111 49. TestCases:
11111111 “status”, “Error”, “contains”, in functions “point_str”.
TESTCASE 2: \r\n.27,24: warning, incompatible implicit declaration of
Input: built in function „matrix‟
1 50. QUESTION:
Expected Return Value: You are required to fix all logical errors in the given code.
11 You can click on
47. QUESTION: Compile &amp; Run anytime to check the
You are required to fix all logical errors in the given code. compilation/execution status of the
You can click on program. You can use System.out.println to debug your
Compile &amp; Run anytime to check the code. The submitted
compilation/execution status of the code should be logically/syntactically correct and pass all
program. You can use System.out.println to debug your test cases. Do not
code. The submitted write the main() function as it is not required.
code should be logically/syntactically correct and pass all Code Approach: For this question, you will need to correct
test cases. Do not the given
write the main() function as it is not required. implementation We do not expect you to modify the
Code Approach: For this question, you will need to correct approach or incorporate
the given any additional library methods.
The function maxReplace(int arr[]) of class MaxArray is Your task is to debug the program to pass all test cases.
supposed to replace every element of the input array arr PROGRAM:
with the maximum element of arr. public class Signal
The function complies successfully but fails to return the {
desired results due to logical errors public static int[] manchester(int arr[])
Your task is to debug the program to pass all the test cases {
PROGRAM: int len=arr.length;
public class MaxArray int res=new int[len];
{ boolean result;
Public static int[] maxReplace(int arr) res[0]=arr[0];
{ for(int i=1;i<len;i++)
int I,len=arr.length;; {
if(len>0) result=(arr[i]==arr[i-1]);
{ res[i]=(result)?1:0;
int max=arr[0]; }
for(i=0;i<len;i++) return res;
{ }
if(max<arr[i]) }
{ 54. TestCase 1:
max=arr[i]; Input:
} 2/5/2013, 2/6/2013
} Expected Return Value:
} 31
51. TestCase 1: TestCase 2:
Input: Input:
[2,5,8,11,3] 1/6/2011, 1/6/2012
Expected Return Value: Expected Return Value:
[11,11,11,11,11] 366
TestCase 2: 55. QUESTION:
Input: You are a software developer at ABC technologies. You
[3,2,5,8,9,11,23,45,63] are supposed to enhance the functionality of a particular
Expected Return Value: module which control a functionality based on date of
[63,63,63,63,63,63,63,63,63] logging.
52. PROGRAM: Given two date, your task is to write a method which
int multiplyNumber(int a, int b, int c) calculates the difference between them. The difference
{ (which shall always be zero o0r a positive number) would
int result, min, max, mid; then be used by another module to perform checks on
max=(a>b)?a>c)?a:c): (b>c)?b:c; logging.
min(a<b?((a<c)?a:c): ((b<c)?b:c); Developer at ABC technologies already use a pre-defined
mid=(a+b+c)-(min+max) class date containing day, month and year as members and
result=(max*int mid) also a collection of method for performing some common
return result; operations. You are supposed to make use of these methods
} to calculate and return the difference.
53. QUESTION: (Please refer to the Helper Code tab for details regarding
The method manchester (int arr) of class signal accepts an the class)
array arr as an input. Each element of arr represents a bit 0 The method difference in dates has to be completed which
or 1. The output is an array with the following property for takes two date instances as inputs and returns the
each element in the input array arr. If the bit arr[i] is the difference.
same as arr[i-1], then the element of the output array is 0,iIf PROGRAM:
they are different then its 1. For the first bit in the input int difference_in_dates(Date *date1, Date *date2)
array , assume its previous bit to be 0. This encoding is {
stored and returned in a new array. //write your code here
For e.g if arr is {0, 1, 0, 0, 1, 1, 1, 0} the function should }
return an array {0, 1, 1, 0, 1, 0, 0, 1}. 56. TestCase 1:
The function compiles successfully but fails to return the Input:
desired result due to logical errors. 54
Expected Return Value: The function removeElement( int *arr,int len,int
D index)takes an array arr of length lenas an input. It is
TestCase 2: supposed to return an array len-1 after removing the integer
Input: at the given index in the input arrayarr.If the given index is
78 out of bounds, then this function should return the input
Expected Return Value: array arr
B The function compiles successfully but fails to return the
57. QUESTION: desired result due to logical errors
This method countOccurance (int arr[], int value) of class PROGRAM:
occurrence is supposed to return the count of occurrences int* removeElement( int *arr,int len,int index){
of a number value in the input array arr. The function int i,j;
compiles successfully but fails to return the desired result if(index<len){
due to logical errors. for(i=index;i<len-1;i++){
Your task is to debug the program to pass all test cases. arr[i]=arr[i++];
PROGRAM: }
public class Occurrence{ Int *rarr =(int*)malloc(sizeof(int)*(len-1));
public static int Occurrence (int arr[], int value) For(i=0;i<len-1;i++)
{ Rarr[i]=arr[i];
int i=0, count=0, len=arr.length; Return rarr;
while(i<len){ }
if(arr[i]==value) else
count++; return arr;
} }
return count; 62. TestCase 1:
} Input:
} [3,6,4,1,7,9,1,3,12,15]
58. TestCase 1: Expected Return Value:
Input: [1,1,3,3,4,6,7,9,12,15]
(0) TestCase 2:
Expected Return Value: Input:
2 [3,3,3,3,3,3,3,3,3,3]
TestCase 2: Expected Return Value:
Input: [3,3,3,3,3,3,3,3,3,3]
0{ 63. QUESTION:
Expected Return Value: The method sortArray(int arr[]) of class Selection sort an
-1 integer array arr as input and perform an in place selection
59. TestCase 1: sort .The function an input array sorted as ascending order
Input: The function compiles fine but to return desired results for
3, [7,0,1,2,0,3,0,4,2,3,0,3,2,1,2,0] some cases
Expected Return Value: Your task to fix the code so but that it passes at test cases
11 Assumption:
TestCase 2: In this particular implementation sort the smallest elements
Input: in the array is swapped with the elements of the next index
2, [2,3,1,3,2,1,4,3,2] and so on
Expected Return Value: PROGRAM:
8 Public class SelectionSort
60. PROGRAM: {
public class LeastDecentPage Public static int[] sortArray(int arr[])
{ {
//Method statement here int x=0,y=0,n=arr.length;
public static int iruCount(int num_cache_wise,int[] pages) for(x=0;x<n;x++)
{ {
//Insert your code here int index_of_min = x;
} for(y=x;y<n;y++)
} {
61. QUESTION: If(arr[index_of_min]>arr[x])
{ public static void printCharacterPattern(int num)
Index_of_min=y; {
} int i, j, value=1;
} char ch= „a‟;
Int temp=arr[x]; char print;
Arr[x]=arr[index_of_min]; for(i=0;i<num;i++)
arr[index_of_min]=temp; {
} print=ch;
return arr; for(j=0;j<=i;j++)
} System.out.print((ch++));
} System.out.println();
64. QUESTION; }
The function getarraysum(int * arr,int len)is supported to }
calculation and return the sum of elements of the input }
array arr of length len(len>0) 67. PROGRAM:
The function compiles successfully but fails to return the int* removeElement( int *arr,int len,int index){
desired result due to logical errors. int i,j;
PROGRAM: if(index<len){
Int getarraysum(int *arr,int len){ for(i=index;i<len-1;i++){
Int sum = 0; arr[i]=arr[i++];
For(i=0;i<len;i-i-1) }
{ Int *rarr =(int*)malloc(sizeof(int)*(len-1));
Sum = arr[i]; For(i=0;i<len-1;i++)
} Rarr[i]=arr[i];
Return sum; Return rarr;
} }
65. QUESTION: else
The method median(int arr[]) of class Median accepts an return arr;
integer array arr. It is supposed to calculate and return the }
median of elements in the input array. 68. TestCase 1:
However, incomplete code in the method median (int arr[]) Input:
works only for odd length arrays. [1,2,3,4,5,6,7,8,9], 9,3
PROGRAM: Expected Return Value:
public class Median [1,2,3,5,6,7,8,9]
{ TestCase 2:
public static int median(int arr[]) Input:
{ [11,23,12,34,54,32], 6,6
int start_index=0; Expected Return Value:
int len=arr.length; [11,23,12,34,54,32]
int end_index=len-1; 69. PROGRAM:
int res=-1; int countElement(int arr,int len,int n)
if(len%2!=0) {
{ int i,count=0;
int median_order=((len+1)/2); for(int i=0;i<len;i++)
medianCalculate ob=new {
medianCalculate(arr,start_index,end_index,median_order); if(arr[i]>(2*n))
res=ob.quick_select(); {
} Count+=1;
else }
{ return count;
} }
return res; 70. TestCase 1:
} Input:
} [-2,-4,-3,-5,-6,-7,-8], 3
66. PROGRAM: Expected Return Value:
public class CharacterPattern{ 0
TestCase 2: temp=arr[i];
Input: arr[i]=arr[j];
[22,55,66,33,44,77], 13 arr[j]=temp;
Expected Return Value: }
5 }
71. TestCase 1: }
Input: return arr;
[2,40,23,52,37], 5 }
Expected Return Value: public static int findMinElement(int arr[i],int arr2[j])
37.000000 {
TestCase 2: return 1;
Input: }
[2,12,5,9], 4 }
Expected Return Value: 74. TestCase 1:
7.000000 Input:
72. TestCase 1: 3, [7,0,1,2,0,3,0,4,2,3,0,3,2,1,2,0], 16
Input: Expected Return Value:
[1,1,0,0,1,0], 6 11
Expected Return Value: TestCase 2:
[1,0,1,0,1,1] Input:
TestCase 2: 2, [2,3,1,3,2,1,4,3,2], 9
Input: Expected Return Value:
[0,0,0,1,0,1,1,1], 8 8
Expected Return Value: 75. PROGRAM:
[0,0,0,1,1,1,0,0] int* cellCompete(int* cells,int days)
73. QUESTION: {
You are required to complete the given code by reusing //Write tour code here
existing functions .you can click on complie and run any }
time to check the compilation / execution status of the //Function signature ends
program you can use System.out.println to debug your 76. PROGRAM:
code. The submitted code should be logically/syntactically char checkGrade(int score)
correct and pass all testcases .do not write the main() {
function has it is not required if(score<=60)
Code Approach: For this question you will need to return „D‟;
complete the code as in given implementation.we don‟t else if((61<=score)&&(score<=75))
expect you to modify the approach The return „C‟;
methodfindMinElement(int arr1[i],int arr2[]) of else if((76<=score)&&(score<=90))
class MinArray accepts two integer array arr1,arr2 it is return „B‟;
supposed to return the smallest elements in both the input else
arrays Another method sortArray(int arr[]) sorts the return „A‟;
input array arr in ascending order and returns It Your task }
is to use sortArray(int arr[]) method and complete the 77. QUESTION :
code inFindMinElement(int arr1[],int arr2[]).so that it You are required to fix all logical errors in the given code.
possible all test cases. You can click on
PROGRAM: Compile &amp; Run anytime to check the
Public class MinArray compilation/execution status of the
{ program. You can use System.out.println to debug your
Public static int[] sortArray(int[] arr) code. The submitted
{ code should be logically/syntactically correct and pass all
int i=0,j=0,temp=0,index=0; testcases. Do not
for( i=0;i<arr.length;i++) write the main() function as it is not required.
{ Code Approach: For this question, you will need to correct
for(j=i+1;j<arr.length;j++) the given
{ implementation. We do not expect you to modify the
if(arr[i]>arr[j]) approach or incorporate
{ any additional library methods.
The method deleteDuplicate(int arr[]) of class Expected return value:
DistinctArray takes an array as an input it is supposed to [0,0,0,0,0,1,1,0]
remove duplicates integers from the input array arr such 80. TESTCASE 1:
that for each distinct integer the first occurrence is retained Input:
and all the duplicates elements following it are removed for [[5,6],[11,14],[23,27]]
Example given input array (2,3,2,2,5,6,6,7) the expected Expected return value:
output is (2,3,5,6,7) 5
The function complies successfully but fails to return the TESTCASE 2
desired results due to logical errors Input:
Your task is debug the program to pass all the test cases [[3,1,7],[2,5,4],[7,8,9]]
PROGRAM: Expected return value:
Public class DistinctArray{ 17
Public static int[] deleteDuplicate (int arr[]) 81. QUESTION:
{ You are required to fix all logical errors in the given code.
int count=0,p,len=arr.length ,i,j,k,originalLength=len; You can click on
for(i=0;i<len;i++) Compile &amp; Run anytime to check the
{ compilation/execution status of the
for(j=i+1;j<len;j++) program. You can use System.out.println to debug your
{ code. The submitted
if(arr[j]==arr[i]) code should be logically/syntactically correct and pass all
{ testcases. Do not
arr[k]=arr[k+1]; write the main() function as it is not required.
} Code Approach: For this question, you will need to correct
len=len-1; the given
count=count+1; implementation. We do not expect you to modify the
j=i; approach or incorporate
} any additional library methods.
} Lisa always forgets her birthday which is on 5 Th july
} In order to help her we have
return (int*)arr; function CheckBirthDay(char *month,int day) which
} takes day and month as inputs and returns 1 if its her
78. QUESTION: birthday and returns a 0 otherwise
You are given a pre-defined structure primebank and also The function compiles fine but to return desired results for
a collection of related functions which can be used to some cases
perform some basic operations on the structure Your task to fix the code so but that it passes at test cases
PROGRAM: PROGRAM:
Import java.lang.Math; int CheckBirthDay(char *month,int day)
public class Prime {
{ if(strcmp(month,”july”)||(day=5))
Public static void printPrime(int num1,int n) {
{ return 1;
//Write your code here }
} else
} {
79. PROGRAM: return 0;
Int* cellcompete(int* cells, int days) }
{ 82. PROGRAM:
} Public class Digitsum
TESTCASE 1: {
Input: Public static int getDigitSum(int arr[i])
[1,0,0,0,0,1,0,1], 1 {
Expected return value: Int result,len=arr.length;
[0,1,0,0,1,0,1,0] For(int i=0;min=arr[0];i&lt;len;i++)
TESTCASE 2 {
Input: if(arr[i]&lt;min)
[1,1,1,0,1,1,1,1],2 min=arr[i];
} int i, temp, orginallen=arr.length;
results=getSum(min) int len=orginallen;
if(results%2==0) for(i=0;i&lt;orginallen/2;i++)
return 1; {
else temp=arr[len-1];
min==arr[j]; arr[len-1]=arr[i];
} arr[i]=temp;
} len+=1;
} }
83. TestCase 1: return arr;
Input: }
(3,4),(2,1),(1,5) }
Expected Return Values: 87.Question
1 Problem
TestCase 2: The function countDigits (int num) is supposed to reurn
Input: the remainder when
(1,-1),(0,-1),(1,-1) the input argument num (num&gt;0) is divided by the
Expected Return Values: number of digits in sum.
0 The function compiles successfully but fails to return the
84. TestCase 1: desired result due to
Input: logical errors.
[2,2,3,3,4,4] Your task is to debug the program to pass all test cases.
Expected return Value: PROGRAM:
[2,3,4] Public class Digits{
TestCase 2: Public static int countDigits(int num){
Input : int countDigits(int num){
[21,21,21,21,21] int count=0;
Expected return Value: while(num!=0){
[21] num=num/10;
85. TestCase 1: count++;
Input: }
[1,2,3,4,5,6,7] return (num%count);
Expected Return values:
[7,6,5,4,3,2,1] }
TestCase 2: 88.Question
Input : Problem
[2,8,4,6] The Function reverseArray(int arr[])of class sort Array arr
Expected Return values: of an arguments
[6,4,8,2] For example, if the input array arr is {20,30,10,40,50} the
86.Question function is expected
TESTCASE to return{50,40,10,30,20}
TestCase 1: The function compiles successfully but fails to return the
Input : desired result due to
[1,2,3,4,5,6,7] logical errors
Expected Return Values : PROGRAM:
[7,6,5,4,3,2,1] int arrayReverse(int *arr,int len){
TestCase 2: int i,temp,originallen=len;
Input: for(i=0;i&amp;lt;=i&amp;lt;=originallen/2;i++){
[2,8,4,6] temp=arr[len-1];
Expected Return Values arr[len-1]=arr[i];
[6,4,8,2] arr[i]=temp;
Program len-=1;
public class SortArray }
{ }
public static int[] reverseArray(int arr[]) 89.Question
{ TestCase
For examples if n=4 the pattern is
Testcase 1 a
Input: ab
[-2,-4,-3,-5,-6,-7,-8] -3 abc
Expected return values abcd
0
Testcase 2 Program
Input: public class CharacterPattern{
[22,55,66,33,44,77] .13 public static void printCharacterPattern(int num)
Expected return values {
5 int i, j, value=1;
Program char ch= „a‟;
char print;
Public class Elementcount for(i=0;i&lt;num;i++)
{ {
Public static int countelement(int arr[],int n) print=ch;
{ for(j=0;j&lt;=i;j++)
Int I,count=0,len=arr.length; System.out.print((ch++));
For(i=0;i<len;i++) System.out.println();
{ }
If(arr[i]=2n) }
Count=-1; }
} 92.Question
return count ; Problem
} You are required to fix all logical errors in the given code.
} You can click
90.Question onCompile &amp;amp;amp; Run anytime to check the
TESTCASES compilation/execution status of the program. You can use
TESTCASE 1: System.out.println to debug your code. The
Input: submittedcode should be logically/syntactically correct and
2/5/2013, 2/6/2013 pass all testcases.
Expected Return Value: Do not write the main() function as it is not required.
31 Code Approach: For this question, you will need to
TESTCASE 2: correct the given
Input: implementation. We do not expect you to modify the
1/6/2011, 1/6/2012 approach or incorporate
Expected Return Value: any additional library methods.
366 The Least-Recently-Used(LRU) cache algorithm exists the
91.Question element from the cache(when it&#39;s full)
Problem that was least-recently-used. After an element is requested
You are required to fix all logical errors in the given code. from the cache, it should be added to
You can click the cache (if not already there) and considered the most-
onCompile &amp;amp;amp; Run anytime to check the recently-used element in the cache.
compilation/execution statusof the program. You can use Given the maximum size of the cache and a list of
System.out.println to debug your code. The integers(to request from the
submittedcode should be logically/syntactically correct and cache), calculate the number of cache misses using
pass all testcases. the LRU cache algorithm. A
Do not write the main() function as it is not required. cache miss occur when the requested integer does not exist
Code Approach: For this question, you will need to correct in the cache.
the given Initially, the cache is empty.
implementation. We do not expect you to modify the The input to the function lruCountMiss shall consist of an
approach or incorporate integer
any additional library methods. max_cache_size, an array pages and its length len.
The method printCharacterPattern(int n) of class The function should return an integer for the number of
characterPattern is expected to print the first n (26>n>0) cache misses using
lines of the pattern the LRU cache algorithm.
Assume that the array pages always has pages numbered {
from 1 to 50. Int result,min,max,mid;
93.Question Max=(a&gt;b)?a&gt;c?a:cLb&gt;c)?b:c);
TESTCASE Min=(a&lt;b)?((a&lt;c)?a:c((b&lt;c)?b:c);
TestCase 1 Mid=(a+b+c)-(min+max);
Input: Result=(max*int mid);
[1,1,0,0,1,1,1],6 Return result;
Expected Return Values }
[1,0,1,0,1,1] }
TestCase 2 95.TESTCASES
Input: TESTCASE 1
[0,0,0,1,0,1,1,1],8 Input
Expected return Values 5,7,4
[0,0,0,1,1,1,0,0] Expected return value:
35
Program TESTCASE 2
int * manchester(int* arr,int len){ Input
int*res=(int*)malloc(sizeof(int)*len); 11,12,13
for(int i=0;i<len;i++) Expected return value:
{ 156
res[i]=(arr[i]==arr[i-1]); 96.Question
} TESTCASES
Return res;
}
94.Question TestCase 1
Problem
You are required to complete the given code by reusing Input:
existing functions youcanclick on complie and run any time 4
to check the compilation / executionstatus of the program Expected Return value:
you can use System.out.println to debug your code. 11
Thesubmitted code should be logically/syntactically correct 1111
and pass all testcases.do not write the main() function has it 111111
is not required 11111111
Code Approach :For this question you will need to TestCase 2:
complete the code as in Input:
given implementation.we don‟t expect you to modify the 1
approach Expected Return Value:
You are given a pre-defined structure Point and also a 11
collection of related 96.Program
functions which can be used to perform some basic Void drawPrintPattern(int n)
operations on the structure. {
You will have to implement the int i,j,print=1;
function isRightTriangle(Ppoint *P1, Point for(i=1;i<=n;i++){
*P2,Point *P3) which accepts 3 points as input and checks for(j=1;j<=2*I;j++)
whether the given 3 printf(“%d”,print);
points can make a right angle triangle or not. printf(“\n”);
If they make a right angle triangle the function returns 1 }
else if returns 0 }
You are supposed to use point structure and associated 97.Question
fuction for the task Problem
You are required to fix all logical errors in the given code.
95.Question You can click on
Program Compile &amp;amp;amp; Run anytime to check the
Public class Multipation compilation/execution status of the program. You can use
{ System.out.println to debug your code. The submittedcode
Public ststic int multiplynumber(int a,int b,int c)
should be logically/syntactically correct and pass all }
testcases. 99.Question
Do not write the main() function as it is not required. TESTCASES
Code Approach: For this question, you will need to correct TestCase 1 :
the given Input:
implementation. We do not expect you to modify the [3,6,4,1,7,9,1,3,12,15]
approach or Expected Return values
incorporateany additional library methods. [15,12,9,7,6,4,3,3,1,1]
The function drawprintPattern(int n) is expected to print
the first n(n&gt;0) lines of the pattern shown below TestCase 2
For Example ,if n=3 the pattern should be Input:
11 [3,3,3,3,3,3,3,3,3]
1111 Expected return Values :
111111 [3,3,3,3,3,3,3,3,3]
The function complies successfully but fails to return the
desired results due to Program
logical errors Public class SelectionSort
Your task is to debug the program to pass all the testcases {
Program Public static int[] sortArray(int arr[])
{
Void drawPrintPattern(int n) int x=0,y=0,n=arr.length;
{ for(x=0;x&lt;n;x++)
int i,j,print=1; {
for(i=1;i<=n;i++){ int index_of_min = x;
for(j=1;j<=2*I;j++) for(y=x;y&lt;n;y++)
printf(“%d”,print); {
printf(“\n”); If(arr[index_of_min]&gt;arr[x])
} {
98.Question Index_of_min=y;
Problem }
You are required to fix all logical errors in the given code. }
You can click on Int temp=arr[x];
Compile &amp;amp;amp; Run anytime to check the Arr[x]=arr[index_of_min];
compilation/execution status of the program. You can use arr[index_of_min]=temp;
System.out.println to debug your code. The submittedcode }
should be logically/syntactically correct and pass all return arr;
testcases. }
Do not write the main() function as it is not required. }
Code Approach: For this question, you will need to correct 100.Question
the given Problem
implementation. We do not expect you to modify the Problem
approach or You are required to fix all logical errors in the given code.
incorporateany additional library methods. You can click on
The function countOccurrence(int *arr,int len,int value) is Compile &amp;amp;amp; Run anytime to check the
supposed to return the count of occurences of number compilation/execution status of the program. You can use
value in the input array arr of length (len>0) System.out.println to debug your code. The submittedcode
The function compiles successfully but fails to return the should be logically/syntactically correct and pass all
desired resukts due to logical errors testcases.
Program Do not write the main() function as it is not required.
Int countOccurrence(int *arr,int len,int value){ Code Approach: For this question, you will need to correct
Int i=0;count=0; the given
While(i=len){ implementation. We do not expect you to modify the
If(arr[i]==value) approach or
Count=1; incorporateany additional library methods.
} The method median(int arr[]) of class Median accepts an
return count; integer array arr. It is
supposed to calculate and return the median of elements in You are required to fix all logical errors in the given code.
the input array. You can click on
However, incomplete code in the method median (int arr[]) Compile &amp;amp;amp; Run anytime to check the
works only for odd compilation/execution status of the program. You can use
length arrays. System.out.println to debug your code. The submittedcode
Program should be logically/syntactically correct and pass all
Float median(int * arr,int len) testcases.
{ Do not write the main() function as it is not required.
int start_index=0; Code Approach: For this question, you will need to correct
int end_index=len-1; the given
float res = -1; implementation. We do not expect you to modify the
if(len%2!=0) approach or
{ incorporateany additional library methods.
Int median_order = ((len+1)/2);
Res=(float)quick_select(arr,start_index,end_index,median- The method sortArray(int arr[]) of class Selection sort an
order) integer array arr as
} input and perform an in place selection sort .The function
Else an input array sorted
{ as ascending order
} The function compiles fine but to return desired results for
Return res; some cases
} Your task to fix the code so but that it passes at test cases
} Assumption:
101.Question In this particular implementation sort the smallest elements
PROGRAM in the array is
public calss AllExponent swapped with the elements of the next index and so on
{
public static float allExponent( int base,int exponent ) Program
Public class SelectionSort
{ {
float res=1; Public static int[] sortArray(int arr[])
if(exponent &gt;=0) {
{ int x=0,y=0,n=arr.length;
Exponent exp=new Exponent(base,exponent); for(x=0;x&lt;n;x++)
res = (float)exp.positiveExponent(); {
} int index_of_min = x;
else for(y=x;y&lt;n;y++)
res=0; {
} If(arr[index_of_min]&gt;arr[x])
return res; {
} Index_of_min=y;
} }
TESTCASE }
TestCase 1; Int temp=arr[x];
Input Arr[x]=arr[index_of_min];
5,2 arr[index_of_min]=temp;
Expected Return Value: }
25.000000 return arr;
TestCase 2: }
Input }
5,-2 103.Question
Expected Return Values: TESTCASES
0.040000 TestCase 1
102.Question Input:
Problem [[3,2,1],[4,6,5],[7,8,9],3,3
Expected return Values:
45 105.Question
TestCase2 TESTCASES
Input: TestCase 1:
[[3,12,10,[14,61,51],[21,84,95],3,3 Input :
Expected return Values: 3
357 Expected return values :
Program 1
11
111
TestCase 2:
Int matrixsum( int &amp;matrix, int m, int n ) Input
{ 1
Int i,j,sum=0; Expected Return values
For(i=0;i&lt;m;i++) 1
{ Program
For(j=0;j&lt;n;j++) Void patternPrint(int n)
Sum + =matrix(i)(j); {
} Int print=1,I,j;
Return sum; For(i=0;i<n;i++)
} {
104.question For(j=0;j<=i;j++)
Problem {
You are required to fix all logical errors in the given code. Printf(“%d”,print);
You can click on }
Compile &amp;amp;amp; Run anytime to check the Printf(“\n”);
compilation/execution status of the program. You can use }
System.out.println to debug your code. The submittedcode }
should be logically/syntactically correct and pass all 106.Question
testcases. TESTCASES:
Do not write the main() function as it is not required. TestCase 1:
Code Approach: For this question, you will need to Input:
correct the given implementation. We do not expect you to (3,4),(2,1),(1,5)
modify the approach or incorporateany additional library Expected Return Values:
methods. 1
The function patternPrint(int n) is supposed to print n TestCase 2
number of lines in the following pattern Input:
For n=4 the pattern should be (1,-1),(0,-1),(1,-1)
1 Expected Return Vlaues
11 0
111 107.Question
1111 Problem
The function compiles line by to return the desired results You are required to fix all logical errors in the given code.
for some testcases You can click on
Compile &amp;amp;amp; Run anytime to check the
Program compilation/execution status of the program. You can use
Void patternPrint(int n) System.out.println to debug your code. The submittedcode
{ should be logically/syntactically correct and pass all
Int print=1,i,j; testcases.
For(int i=0;i&lt;n;i++) Do not write the main() function as it is not required.
{ Code Approach: For this question, you will need to
For(j=0;j&lt;=i;j++) correct the given implementation. We do not expect you to
{ modify the approach or incorporateany additional library
Printf(“%d”,print);} methods.
} You are given a pre- defined structure Point and also a
Print(“\n”); collection of related
}
function which can be used to perform some basic Temp=arr[i];
operations on the structure. arr[i]=arr[j];
You will have to implement the function is Triangle(Point arr[j]=temp;
*p1, Point *p2, Point }
*p3) which accepts 3 points as input and checks whether }
the given 3 pointsfrom the vertices of a triangle. }
If they form a triangle the function returns 1else it returns return arr;
0. }
You are supposed to use point structure and associated 110.Question
functions for this task. TESTCASE
(Please refer to the Helper Code tab details regarding the TestCase 1:
structure point and the Input:
predefined functions around it) [1,2,3,4,5,6,7,8,9], 3
108.Question Expected Return Value:
TESTCASES [1,2,3,4,5,6,7,8,9]
TestCase 1; TestCase 2:
Input Input:
July 13 [11,23,12,34,54,32], 6
Expected Return Value: Expected Return Value:
0 [11,23,12,34,54,32]
TestCase 2: Program
Input public class ShortArray{
April 3 public static int[] removeElement(int arr[], int index)
Expected Return Value:
0 {
Program int i, j, len=arr.length;
Int checkBirthday(char* month,int day) if(index&lt;len)
{ {
for(i=index;i&lt;len;i++)
If(strcmp(month,”july”)||(day-5)) arr[i]=arr[i++];
Return 1; int rarr[]=new int[len-1];
Else for(i=0;i&lt;len;i++)
Return 0; rarr[i]=arr[i];
} return arr;
109.Question }
TESTCASES else
TestCase 1 : return arr;
Input: }
[3,6,4,1,7,9,1,3,12,15] }
Expected Return values 111.Question
[15,12,9,7,6,4,3,3,1,1] Problem
TestCase 2 You are required to fix all logical errors in the given code.
Input: You can click on
[3,3,3,3,3,3,3,3,3] Compile &amp;amp;amp; Run anytime to check the
Expected return Values : compilation/execution status of the program. You can use
[3,3,3,3,3,3,3,3,3] System.out.println to debug your code. The submittedcode
Program should be logically/syntactically correct and pass all
testcases.
Int *descendingSortArray(int *arr,int len){ Do not write the main() function as it is not required.
Int small,pos,i,j,temp; Code Approach: For this question, you will need to
For(int i=0li<len;i++){ correct the given implementation. We do not expect you to
For(j=i;j<len;j++){ modify the approach or incorporateany additional library
Temp=0; methods.
If(arr[i]<arr[j]){ The method findMaxelement(int arr1[],int arr2[]) of class
Temp=0; MaxArrayElement accepts two integers arrays arr1,arr2.
If(arr[i]<arr[j]){
It is supposed to return the largest elements in both of input arr[i]=arr[i++];
arrays int rarr[]=new int[len-1];
Another method sortArray(int arr[]) sorts the input array arr for(i=0;i&lt;len;i++)
in ascending order and returns the sorted array rarr[i]=arr[i];
Program return arr;
Public class MaxArrayElement }
{ else
Public static int[] sortArray(int[] arr) return arr;
{ }
Int i=0,j=0,temp=0,index=0; }
For(i=0;i<arr.length;i++){ 113.Question
For(j=i+1;j<arr.length;j++){ TESTCASE
If(arr[i]>arr[j]) TestCase 1:
{ Input:
Temp=arr[i]; 782
arr[i]=arr[j]; Expected Return Value:
arr[j]=temp; 2
} TestCase 2:
} Input:
} 21340
return arr; Expected Return Value:
} 0
112.Question Program
Problem Public class Digits
You are required to fix all logical errors in the given code. {
You can click on Public static int countDigit(int num){
Compile &amp;amp;amp; Run anytime to check the Int count=0;
compilation/execution status of the program. You can use While(num!=0){
System.out.println to debug your code. The submittedcode Num=num/10;
should be logically/syntactically correct and pass all Count++;
testcases. }
Do not write the main() function as it is not required. Return (num%count);
Code Approach: For this question, you will need to }
correct the given implementation. We do not expect you to }
modify the approach or incorporateany additional library 114.Question
methods Problem
The methods removeElement(int arr[],int index) of class You are required to fix all logical errors in the given code.
shortArray takes an array arr in the input.it supposed to You can click on
return on array after removing the elements index in the Compile &amp;amp;amp; Run anytime to check the
input array arr. compilation/execution status of the program. You can use
The function compiles line by to return the desired results System.out.println to debug your code. The submittedcode
for some testcases should be logically/syntactically correct and pass all
testcases.
Assumptions: Do not write the main() function as it is not required.
The input index is always a non negative integer. Code Approach: For this question, you will need to
Zero based indexing is followed to access array elements correct the given implementation. We do not expect you to
modify the approach or incorporateany additional library
methods
Program The Function reverseArray(int arr[])of class sort Array arr
public class ShortArray{ of an arguments
public static int[] removeElement(int arr[], int index) For example, if the input array arr is {20,30,10,40,50} the
{ function is expected
int i, j, len=arr.length; to return{50,40,10,30,20}
if(index&lt;len) The function compiles successfully but fails to return the
{ desired result due to
for(i=index;i&lt;len;i++) logical errors
Program submittedcode should be logically/syntactically correct and
public class SortArray pass all testcases.
{ Do not write the main() function as it is not required.
public static int[] reverseArray(int arr[])
{
int i, temp, orginallen=arr.length; Code Approach: For this question, you will need to correct
int len=orginallen; the given
for(i=0;i&lt;orginallen/2;i++) implementation. We do not expect you to modify the
{ approach or incorporate
temp=arr[len-1]; any additional library methods.
arr[len-1]=arr[i]; The method printCharacterPattern(int n) of class
arr[i]=temp; characterPattern is expected to print the first n (26>n>0)
len+=1; lines of the pattern
} For examples if n=4 the pattern is
return arr; a
} ab
115.Question abc
TESTCASE abcd
TESTCASE 1: The function compiles successfully but fails to return the
Input: desired result due to logical errors
5
Expected output: Program
a public class CharacterPattern{
ab public static void printCharacterPattern(int num)
abc {
abcd
abcde int i, j, value=1;
TestCase 2: char ch= „a‟;
input: char print;
1 for(i=0;i&lt;num;i++)
Output: {
A print=ch;
Program for(j=0;j&lt;=i;j++)
public class CharacterPattern{ System.out.print((ch++));
public static void printCharacterPattern(int num) System.out.println();
{ }
}
int i, j, value=1; }
char ch= „a‟; 117.Question
char print; Problem
for(i=0;i&lt;num;i++) You are required to fix all logical errors in the given code.
{ You can click
print=ch; onCompile &amp;amp;amp; Run anytime to check the
for(j=0;j&lt;=i;j++) compilation/execution statusof the program. You can use
System.out.print((ch++)); System.out.println to debug your code. The
System.out.println(); submittedcode should be logically/syntactically correct and
} pass all testcases.
} Do not write the main() function as it is not required.
} Code Approach: For this question, you will need to correct
116.Question the given
Problem implementation. We do not expect you to modify the
You are required to fix all logical errors in the given code. approach or incorporate
You can click any additional library methods.
onCompile &amp;amp;amp; Run anytime to check the The method countelement(int arr[],int n) of class
compilation/execution statusof the program. You can use ElementCount is supposed to return the number of elements
System.out.println to debug your code. The in the array arr which are greater than inputs
Program You are required to fix all logical errors in the given code.
Public class Elementcount You can click
{ onCompile &amp;amp;amp; Run anytime to check the
Public static int countelement(int arr[],int n) compilation/execution statusof the program. You can use
{ System.out.println to debug your code. The
Int I,count=0,len=arr.length; submittedcode should be logically/syntactically correct and
For(i=0;i<len;i++) pass all testcases.
{ Do not write the main() function as it is not required.
If(arr[i]=2n) Code Approach: For this question, you will need to correct
Count=-1; the given
} implementation. We do not expect you to modify the
return count ; approach or incorporate
} any additional library methods.
118.Question The method maxReplacement(int arr[]) of
class MaxArray is supposed to replace every element of
TESTCASES the input array arr with the maximum element of arr.
TestCase 1 The method looks time but gives a compilation error
Input: Program
[-2,-4,-3,-5,-6,-7,-8],3 Public class MaxArray
Expected Return value: {
0 Public static int[] maxReplace(int arr)
TestCase 2 {
Input [22,55,66,33,44,77],13 Int i,len-arr.length;
Expected Return Values: If(len>0)
5 {
119.Question Int max=arr[0];
TESTCASES For(i=0;i<len;i++)
TestCase 1 {
Input: If(max<arr[i])
[23,12,14,24,21] {
Expected Return values : Max=arr[i];
[24,23,21,14,21] }
TestCase 2 }
Input: }
[1,1,1,1,1] 121.Question
Expected return Values: TESTCASE
[1,1,1,1,1] TestCase 1;
Program Input
Public class Arraysort 5,2
{ Expected Return Value:
Public static int[] sortArray(int arr[]){ 25.0
Int i,max,location,j,len=arr.lemgth; TestCase 2:
For(i=0;i<len;i++) Input
{ 5,-2
Max=arr[i]; Expected Return Values:
Location=j; 0.04
} Program
} public calss AllExponent
Temp=arr[i]; {
Arr[i]=arr[location]; public static float allExponent( int base,int exponent )
} {
return arr; float res=1;
} if(exponent &gt;=0)
} {
120.Question Exponent exp=new Exponent(base,exponent);
Problem res = (float)exp.positiveExponent();
} Expected Return values :
else 27
res=0; Program
} Int calculationMatrixsum(int **matrix,int m, int n)
return res; {
} Int i, j , sum=0,row=m,column = n;
} If((row&gt;0)&amp;&amp;(column&gt;0))
122.Question {
TESTCASE For(i=0;i&lt;row;i++)
TestCase1: {
Input: Sum = 0;
Time:1:58:42,Time:2:1:45 For(j=0;j&lt;column;j++)
Expected Return values: {
183 if(i==j)
Testcase 2 {
Input: If(matrix*[i][j]/2!=0)
Time:3:49:57,Time:2:45:57 Sum += matrix[i][i];
Expected Return Values }
3600 }
123.Question }return sum;
Problem }
You are required to fix all logical errors in the given code. 125.Question
You can click Problem
onCompile &amp;amp;amp; Run anytime to check the You are required to fix all logical errors in the given code.
compilation/execution statusof the program. You can use You can click
System.out.println to debug your code. The onCompile &amp;amp;amp; Run anytime to check the
submittedcode should be logically/syntactically correct and compilation/execution statusof the program. You can use
pass all testcases. System.out.println to debug your code. The
Do not write the main() function as it is not required. submittedcode should be logically/syntactically correct and
Code Approach: For this question, you will need to correct pass all testcases.
the given Do not write the main() function as it is not required.
implementation. We do not expect you to modify the Code Approach: For this question, you will need to correct
approach or incorporate the given
any additional library methods. implementation. We do not expect you to modify the
You are a software developer at XYZ Technologies. You approach or incorporate
are supposed to any additional library methods.
enhance the functionality of a particular module which The function calculateMatrixSum(int ** matrix, int m, int
control a functionality n) accepts a two
based on date of logging. dimensional array matrix of dimensions m, n as input and
Given two time stamps.your task is to written a method returns the sum of
which calculates the differences between them.The odd elements whose i th and j th index are same.
differences (which shall always be zero or a positive The function compiles line but falls to return the desired
number ) should be then used by another modules checks of result for some test
logging cases.
Developers at XYZ Technologies already use a pre defined
classes 126.Question
124.Question Problem
TESTCASE The function replaceValues(int *arr) of class
TestCase 1 ArrayOperation accepts an
Input: array arr of length len (len&gt;0) as an input and returns an
[[5,6],[11,14][23,27]] array of the same
Expected return Values: length.
5 If the length of arr is off, all the elements of arr are
TestCase 2 supposed to be replaced by
Input: 1 st and in case it is even, the elements should be replaced
[[3,1,7],[2,5,4],[7,8,9] by 0s.
For example: given the input array {0, 1, 2} the function element in both the input arrays. Another
will return the array function sortArray(int *arr,int len) sorts the input array arr
{1, 1, 1} of length len in ascending order and returns the sorted
The function compiles successfully but fails to return the array.
desired result due to Your task is to use sortArray(int *arr,int len) function and
logical errors. complete the codein findMaxElement(int *arr1,int len1,int
Your task is to debug the program to pass all the test cases. *arr2,int len2) so that it passes all testcases.
Program: PROGRAM
public class ArrayOperation { int *sortArray(int *arr,int *len)
public static int[] replaceValues( int arr[]){ {
int i,j,len=arr.length; int i=0,j=0,temp=0,index=0;
if(len%2==0){ for(i=0;i&lt;len;i++)
for(i=0;i&lt;len;i++) {
arr[i]=0; for(j=i+1;j&lt;len;j++)
} {
else{
for(j=0;j&lt;len;j++) If(arr[i]&gt;arr[j])
arr[j]=1; {
} temp=arr[i];
return arr; arr[i]=arr[j];
} arr[j]=temp;
} }
127.Question }
TESTCASE }
TestCase 1: return arr;
Input: }
[1,2,3,4,5,6,7] 129.Question
Expected Return values Problem
[7,6,5,4,3,2,1] The Function arrayReverse(int *arr,int len) accepts an array
TestCase 2: arr of length len(len
Input : &gt;=0) as an argument.The function is expected to reverse
[2,8,4,6] the elements of the input array in-place.
Expected Return values For example, if the input array arr is {20,30,10,40,50} the
[6,4,8,2] function is expected to
Program return{50,40,10,30,20}
public class sortArray The function compiles successfully but fails to return the
{ desired result due to
Public static int[] reverseArray(int arr[]) logical errors
{ PROGRAM:
int i,temp,origination=arr.lemgth; int arrayReverse(int *arr,int len){
int len=origination; int i,temp,originallen=len;
for(i=0;i&lt;origination/2;i++) for(i=0;i&lt;=i&lt;=originallen/2;i++){
{ temp=arr[len-1];
Temp=arr[len-1]; arr[len-1]=arr[i];
Arr[len-1]=arr[i]; arr[i]=temp;
Arr[i]=temp; len-=1;
Len+=1; }
} Return arr;
return arr; }
} 130.Question
Problem
128.Question This method countOccurance (int arr[], int value) of class
Problem occurrence is supposed
The function findMaxElement(int *arr1,int len1,int to return the count of occurrences of a number value in the
*arr2,int len2) accepts twointeger arrays arr1,arr2 of length input array arr. The
len1,len2 respectively.It is supposed to return the largest
function compiles successfully but fails to return the [1,5,5,2,2,7,8,6,6,9,10],11
desired result due to logical errors. Expected return value:
Your task is to debug the program to pass all test cases. 2
PROGRAM TESTCASE 2:
public class Occurrence{ Input:
public static int Occurrence (int arr[], int value) [13,12,12,13,14],5
{ Expected return value:
int i=0, count=0, len=arr.length; 1
while(i&lt;len){
if(arr[i]==value) 135.Question
count++; Problem
} The function patternPrint(int n) supposed to print n
return count; numberof lines in the
} following pattern.
} For n=4 the pattern should be:
131.Question 1
The function Manchester(int *arr,int len)accepts an array 11
arr of legth len (len&gt;0) as an input.Each element of an 111
represents a bit -0 0\=or 1.The output is an array with the 1111
following property. The function complies successfully but fails to return the
PROGRAM desired results due to
Int * Manchester(int*arr, int len){ logical errors
Int* res = (int*)malloc(sizeof(int)*len); Your task is to debug the program to pass all the testcases
For(int i= 0; i&lt; len; i++){ Program
Res[i]= (arr[i]==arr[i-1]); Void patternPrint(int n)
} {
Return res; Int print=1,i,j;
} For(int i=0;i&lt;n;i++)
132.Question {
TESTCASE For(j=0;j&lt;=i;j++)
TESTCASE 1: {
Input: Printf(“%d”,print);}
(2,4)(4,2)(1,2) }
Expected output Print(“\n”);
0 }
Testcase 2: }
input: 136. Question
(-4,0)(2,0)(-3,-4) Program
Output: Public class Multipation
1 {
133.Question Public ststic int multiplynumber(int a,int b,int c)
int sameelementcount(int * arr, int len) {
{ Int result,min,max,mid;
Int i,count = 0; Max=(a&amp;gt;b)?a&amp;gt;c?a:cLb&amp;gt;c)?b:c);
For(i=0;i&lt;len-1;i++) Min=(a&amp;lt;b)?((a&amp;lt;c)?a:c((b&amp;lt;c)?b:c);
{ Mid=(a+b+c)-(min+max);
if((arr[i]%2==0)&amp;&amp;(arr[i]==arr[i++])) Result=(max*int mid);
count++; Return result;
} }
return count; }
} 137. Question
} Problem
134.Question You are required to fix all logical errors in the given code.
TESTCASE You can click on
TESTCASE 1: Compile &amp;amp;amp;amp; Run anytime to check the
Input: compilation/execution status
of the program. You can use System.out.println to debug Your task to fix the code so but that it passes at test cases
your code. The Assumption:
submittedcode should be logically/syntactically correct and In this particular implementation sort the smallest elements
pass all testcases. in the array is
Do not write the main() function as it is not required. swapped with the elements of the next index and so on
Code Approach: For this question, you will need to
correct the given Program
implementation. We do not expect you to modify the Public class SelectionSort
approach or {
incorporateany additional library methods. Public static int[] sortArray(int arr[])
The method median(int arr[]) of class Median accepts an {
integer array arr. It is int x=0,y=0,n=arr.length;
supposed to calculate and return the median of elements in for(x=0;x&amp;lt;n;x++)
the input array. {
However, incomplete code in the method median (int arr[]) int index_of_min = x;
works only for odd for(y=x;y&amp;lt;n;y++)
length arrays. {
Program If(arr[index_of_min]&amp;gt;arr[x])
Float median(int * arr,int len) {
{ Index_of_min=y;
int start_index=0; }
int end_index=len-1; }
float res = -1; Int temp=arr[x];
if(len%2!=0) Arr[x]=arr[index_of_min];
{ arr[index_of_min]=temp;
Int median_order = ((len+1)/2); }
Res=(float)quick_select(arr,start_index,end_index,median- return arr;
order) }
} }
Else 139. TESTCASES
{ TestCase 1
} Input:
Return res; [[3,2,1],[4,6,5],[7,8,9],3,3
} Expected return Values:
} 45
138. Question TestCase2
Problem Input:
You are required to fix all logical errors in the given code. [[3,12,10,[14,61,51],[21,84,95],3,3
You can click on Compile &amp;amp;amp;amp; Run Expected return Values:
anytime to check the compilation/execution status 357
of the program. You can use System.out.println to debug 140. TestCase 1:
your code. The submittedcode should be Input :
logically/syntactically correct and pass all testcases. 3
Do not write the main() function as it is not required. Expected return values :
Code Approach: For this question, you will need to 1
correct the given 11
implementation. We do not expect you to modify the 111
approach or TestCase 2:
incorporateany additional library methods. Input
The method sortArray(int arr[]) of class Selection sort an 1
integer array arr as Expected Return values
input and perform an in place selection sort .The function 1
an input array sorted
as ascending order
The function compiles fine but to return desired results for
some cases

S-ar putea să vă placă și