Code For Amcat-1

  • Uploaded by: Rohith Spidey
  • 0
  • 0
  • January 2021
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Code For Amcat-1 as PDF for free.

More details

  • Words: 15,731
  • Pages: 70
Loading documents preview...
1) The function/method insertSortedCircularList accepts two arguments - cList, representing the head of the circular linked list whose elements are sorted in ascending order, and val, an integer representing the value to be inserted. This function/method is supposed to insert valto the circular list represented by cList in such a manner that cList remains sorted. The function/methodinsertSortedCircularList uses another function/method printListthat accepts one argument - cList, the head of a circular linked list and prints its elements. The function/method insertSortedCircularListcompiles successfully but fails to return the desired output due to incorrect implementation of the circular linked list. Your task is to fix the code so that it passes all the test cases. Helper Description The following class is used to represent a Circular List Node and is already implemented in the default code (Do not write this definition again in your code) Struct CNode; Typedef struct CNodecnode; Struct CNode { Int value; Cnode* next; }; 2) The function method stackOperationaccepts three arguments – flag, an integer representing the operation push or pop, stack, a list of integers representing the elements of stack and top, an integer representing the top of the stack. If the flag value is 1, the value 1 is inserted on top of the stack, and if the flag value is 2, the topmost element of the stack is deleted. Print a message “StackFull”. If the flag is equal to 1 and the stack is full or else print a message “StackEmpty”. If the flag is equal to 2 and the stack is empty. The function/method compiles successfully but fails to return the desired result for some test cases due to incorrect implementation of functions push and for pop. Your task is to fix the code so that it passes all the test cases. Note: The function/methodstackOperation uses other functions/methods push, which accepts three arguments - data, an integer representing the

element that has to be inserted at the top of the stack; stack, a list of integers representing the elements of stack; top, an integer representing the index of the top of the stack for inserting a new element; maxSize, an integer representing the maximum size of the stack. isFull, which accepts two integers - top, an integer representing the top of the stack; maxSize, an integer representing the maximum size of the stack. isEmpty, which accepts an integer which checks if the stack is empty or not. printStack, which accepts two arguments - stack, a list of integers representing the elements of stack and top, an integer representing the index of the top of the stack for printing the elements of the stack. pop, which accepts two arguments - stack, a list of integers representing the elements of stack and top, an integer representing the top of the stack for deleting an element from the top of the stack The maximum size of the stack is 10. 3) The function getArraySum(int *arr, int len) is supposed to calculate and return the sum of elements of the input array arr of length len (len>=0). The function compiles successfully but fails to return the desired result because of logical errors. Your task is to debug the program so that it passes all the test cases. Assumption. You may assume that sum of the elements of the array arrwil I not exceed the range of its data type.

TestCase 1: Input: [2, 3, 5, 7, 9], 5 Expected Return Value: 26 TestCase 2: Input: [-1, -2, -3, -4, -4, -1], 6 Expected Return Value: -15

4) The function binarySearch(int*arr, int len, int target) performs the binary search algorithm to look for an element target in the input array arr of length len. If the element is found, the function returns the index of target in arr If it is not found, the function returns -1.

The function seems to work well but goes into an infinite loop for some test cases. Your task is to fix the program so that it passes all the test cases. Note: If there is a Time Limit Exceeded error, it can be due to an infinite loop. The current selected programming language is Java. We emphasize the submission of a fully working code over partially correct but efficient code. Once submitted, You cannot review this problem again. You can use System.out.println () to debug your code. The System.out.println() may not work in case of syntax/runtime error. The version of JDK being used is 1.8. A sequence of parenthesis is called balanced, if it consists entirely of pairs of opening/ closing parenthesis(in that order) which is well nested. For example, sequence “(())()”,”()” and “(()(()))” are balanced while “(()” and “((()))(“ are not. Write a method to determine if a given string contains balanced sequence of parenthesis. The input to the method balanced parenthesis of classes. Parenthesis is a string str.for each character in the string will be “(“or “)”. The output is the count of balanced pairs if the sequence is balanced or -1 otherwise. For example, if the input sequence is “(()(()))”, the expected output is 4. Test Case 1: Input: 1 -> 2 -> 3 -> 4 -> null Expected Return Value 1 -> 2 -> 4 -> 3 -> null

Test Case 2: Input: 11 -> 23 -> 16 ->9 ->21 -> null

Expected Return Value 11 -> 23 ->21 ->9 -> 16 -> null Explanation: The length of the output linked list is 5 So, the middle element is the one at (5+1)/2 = 3rd position. 2. getDigitSum( int arr[]) of class DigitSum accepts an integer array arr. It is supposed to calculate the sum of digits of the smallest element in the input array, it returns 1, if the calculated sum is even, otherwise it returns 0. However there is a compilation error in the code. Your task is to fix it so that it program works for all inputs Note: The function getDigitSum uses another function getSum(int num)that returns the sumof digits of the input number num. Test case 1: Input: [91,92,-131,80,40] Expected Return Value: 0 Test case 2: Input: [23,18,11,3] Expected Return Value: 0

You are required to complete the given code by reusing existing functions. Click on Helper Code tab to find out the details of functions/ classes provided for reuse.You can click on Compile & 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 main() function as it is not required. Code Approach: For this question. You will need to correct the given implementation. We do not except, you to modify the approach or incorporate any library methods. You are given a predefined structure PrimeBank structure and also the collection of related functions that can be used to perform some basic operations on the structure. You must implement the function printPrime(int num, int digit) to accept the initial number num and number of digits n as inputs and prints all the prime numbers of n digits starting from the initial number num. Use the Primebank structure and the associated functions for this task. (Please refer to the helper code tab for details regarding the structure PrimeBank and the predefined functions around it). Test Case 1: Input: 891, 3 Expected Return Value [907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997] Test Case 2: Input: 921, 3 Expected Return Value [929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997] You are required to complete the given code by reusing existing functions. Click on Helper Code tab to find out the details of

functions/ classes provided for reuse.You can click on Compile & Run anytime to check the compilation/execution status of the program. You can use System.out.println to debug your code. The submitted code should be logically/syntactically correct and pass all test cases. Do not write main() function as it is not required. Code Approach: For this question. You will need to correct the given implementation. We do not except, you to modify the approach or incorporate any library methods. The function findMinElement( int arr[], int arr2 []) of class MinArray accepts two intger arrays arr1, arr2. It is supposed to return the sallest element in both the input arrays. Another function sortArray ( int arr]) sorts in the input array arr of length len in ascending order returns it. Your task is to use the SortArray( int arr[]) function to complete code in findMinElement(int arr1[], int arr2[]), so that it passes all the test case. Test case 1: Input: [2,5,1,3,9,8,4,6,5,2,3,11],[11,13,3,4,15,17,67,44,2,100,23] Excepted Return Value: 1 Test case 2: Input: [100,22,43,912,56,89,85,234,123,456,234,890,101] Excepted Return Value: 22 You are required to fix all logical errors in the given code. You can click on Compile & Run anytime to check the compilation/execution status of the program. You can use System.out.println to debug your

code. The submitted code should be logically/syntactically correct and pass all test cases. Do not write main() function as it is not required. Code Approach: For this question. You will need to correct the given implementation. We do not except, you to modify the approach or incorporate any additional library methods. The function deleteDupicate(int arr[]) of class DistinctArray takes an array arr as an input. It is supposed to remove duplicate integer from the input array arr such that for each distinct te first occurrence is retained and all the duplicate elements following it or removed, For example, given the input array arr2,3,2,2,5,6,6,7] the expected output is [2,3,5,6,7]. The function compiles successfully but fails to return the desired result because of logical error. Your task is to debug the program so that it passes all the test cases. Test case 1: Input: [2,2,3,3,4,,4] Excepted Return Value: [2,3,4] Test case 2: Input: [21,21,21,21,21] Excepted Return Value: [21]

Code Approach: for this question you will need to correct the given implementation, We do not except you to modify the approach or incorporate any additional library methods. A ternary search tree is defined as a ternary tree in which a search , proceed character by character , compares the current character In the

search string with the character at the current node. If the search character is lexicographically smaller, the search goes to the left child but if the search character is lexicographically larger, the search goes to the right child. When the search character is equal , the search goes to the middle child and proceeds to the next character in the search string. For example, ternary search tree for strings CUP,CAT,CD,CUT C

U

A

P

T D

T

The function/method insertIntoTernaryTree accepts the arguments – tree, representing a ternary tree and input str, a string representing the word to be inserted in the ternary tree and ptr, an integer representing the index of the current character in the inputStr. The function/method is supposed to return the ternary tree node after inserting the word into the tree. The function/ method compiles successfully but fails to return the desired result for some test cases. Your task is to fix the code so that it passes all the test cases. Input:

C

B

A

u

t

a g

u

p

t [c, a, t, s], 0 Expected Return Value: C

B

A

u

t

a g

u

p

t

s

1) The function method stackOperationaccepts three arguments – flag, an integer representing the operation push or pop, stack, a list of integers representing the elements of stack and top, an integer representing the top of the stack. If the flag value is 1, the value 1 is

inserted on top of the stack, and if the flag value is 2, the topmost element of the stack is deleted. Print a message “StackFull”. If the flag is equal to 1 and the stack is full or else print a message “StackEmpty”. If the flag is equal to 2 and the stack is empty. The function/method compiles successfully but fails to return the desired result for some test cases due to incorrect implementation of functions push and for pop. Your task is to fix the code so that it passes all the test cases.

2) The least recently used (LRU) cache algorithm exists the element from the cache(when it’s full) that was least recently used. After an element is requested from the cache, it should be added to the cache (if not already there) and considered the most recently used element in the cache. Given the maximum size of the cache and a list of integers (to request from the cache), calculate the number of cache misses using the LRU cache algorithm. A cache miss occurs when the required integer does not exist in the cache. Initially, the cache is empty. The input to the functionLruCountMiss shall consist of an integer max_cache_size, an array pages and its length len. The function should return an integer for the number of cache misses using the LRU cache algorithm. Assume that the array pages always have pages numbered from 1 to 50. TEST CASES: TEST CASE1: INPUT: 3,[7,0,1,2,0,3,0,4,2,3,0,3,2,1,2,0],16 EXPECTED RETURN 11 TESTCASE 2: INPUT: 2,[2,3,1,3,2,1,4,3,2],9 EXPECTED 8

RETURN

VALUE:

VALUE:

EXPLANATION: The following page numbers are missed one after the other 2,3,1,2,1,4,3,2.This results in 8-page misses.

1) An image is represented by an "m*n" matrix of integers, wherein each integer represents a pixel value Write an algorithm to rotate an image by 90 degrees left or right according to the value of a flag variable. If the flag value is 0, then rotate left if the flag value Is 1, then rotate right. Input The input to the method consists of four arguments img, a matrix of integers representing the pixels of the image; rows, an integer representing the number of rows (m); columns, an integer representing the number of columns (n); flag,an integer representing the rotation of the image Output Return a matrix of integers representing the pixels of the image rotated according to the value of the flag variable Helper Description The following structure is used to represent a bounded2dArray and is already implemented in the default code (Do not write this definition again in your code); 2) You have to encrypt a non-empty string phrase. The encryption adds a "cyclic shift" to each letter. The value of this "cyclic shift" is determined by the position of the letter from the end of its word. The shift value for each letter of a word is its index value (starting from 0) from the right-most character of the word. For example, the shift values in "yum feed" are: yum: m->0, u->1, y->2; feed. d->0, e->1, e->2, f->3 which gives the encryption: avmigfd. Here, adding the shift with value 0 to letter ‘m’ gives ‘m’ + 0 = m; value 1 to ‘u’ gives ‘u’ + 1 = v, value 2 to 'y’ gives ‘y’ + 2 = a and so on. Note that upon reaching the end of the alphabet, the shift wraps around to the beginning(i.e., the shift value for ‘y’ as shown above is ‘a’) Input

The input to the function/method consists of a string Output Return the encrypted string

Note Assume that the input string contains a single space separating a set of words and that a word consists only of lower case letters. 3) A war is happening. The enemy battalion has planted a bomb in your bunker. Your spy has intercepted a message from the enemy. It contains a list with N numbers and a key (K). The numbers are used to construct a sequence that will defuse the bomb. According to your spy, the logic to extract the sequence from the message is to replace each number with the sum of the next K numbers, if the value of K is positive. If the value of K is negative, the number is replaced by the sum of the previous K numbers. The series of numbers is considered in a cyclic fashion for the last K numbers. Write an algorithm to find the sequence that will defuse the bomb Input The input to the function/method consists of three arguments; size, an integer representing the size of the list (N); key, an integer representing the key (K); message, representing the list of integers. Output Return a list of integers representing the sequence that will defuse the bomb Constraints 0 < size <= 10^5 -10^6<= message[i] <= 10^6 0<=i< size Example Input: size = 4 key= 3 message = [4, 2, -5, 11] Output: [8, 10, 17, 1]

Explanation: Stepl: [2, -5, 11] =>8 Step2: [-5, 11, 4] => 10 Step3: [11, 4, 2] =>17 Step4: [4, 2, -5] => 1 \ So, he output is [8,10, 17, 1] Helper Description The following structure is used to represent a boundedarray and is already implemented in the default code (Do not write this definition again in your code)

typedef struct BoundedArray { int size; int *arr; }boundedarray; 4) An increment matrix is one whose elements are the incremented values of an initial value s For example, if the initial value is "s = 1" and the dimensions are "m = 3" and "n = 3," then the increment matrix will be: 123 456 789 Write an algorithm to multiply the original increment matrix with its transpose Input The input to the function/method consists of three arguments: firstValue, a positive integer representing the initial value (s); rows, a positive integer representing the number of rows in the increment matrix (m); columns, a positive integer representing the number of columns in the increment matrix(n); Output Return a two-dimensional matrix of integers obtained from the multiplication of the increment matrix and its transpose. Example Input: firstValue = 1

rows=3 columns=3 Output: 14 32 50 32 77 122 50 122 194 Explanation For firstValue =1, rows=3 and columns=3, the increment matrix will bw 123 456 789 And the transpose matrix will be 147 258 369 Thus, the resultant multiplication matrix will be 14 32 50 32 77 122 50 122 194 Helper Description The following structure is used to represent a bounded2dArray and is already implemented in the default code (Do not write this definition again in your code) /** Encapsulates a two-dimensional array along with its row size and column size. **/ typedef struct bounded2DimensionalArray { int rowSize; int colSize; int **arr; } bounded2dArray; TestCase 1: Input: 3, 4, 2 Expected Output: 25 39 53 67 39 61 83 105 53 83 113 143

67 105 143 181 TestCase 2: Input: 4, 3, 2 Expected Output: 41 59 77 59 85 111 77 111 145 5) The function printable [int num]is supposed to print the first ten multiples of the multiplication table of the input number num The function compiles fine but fails to return the desired result for some test cases Your task is to fix the program so that it passes all the test cases 6) The function/method mergeLists accepts two arguments - listl and list2, representing two singly linked lists whose elements are sorted in ascending order of their values. This function is supposed to return a linked list formed by merging list] and list2 such that the linked list remains sorted. The function/method compiles successfully but fails to return the desired result for some test cases. Your task is to fix the code so that it passes all the test cases HelperDescription The following structure is used to represent a node of the linked list and is already implemented in the default code (Do not write this definition again in your code): struct LNode; typedef struct LNodelnode; struct LNode { int value; lnode* next; }; 7) Design a way to sort a list of positive integers in descending order according to the frequency of the elements. The elements with higher frequency come before those with lower frequency. Elements with the same frequency come the order in which they appear in the given list. Input

The input to the function/method consists of two arguments: size, the number of elements in the list; arr, a list of positive integers. Output Return a list of positive integers sorted according to the frequency of elements present in arr. Example Input Size=19 Arr=[1,2,2,3,3,3,4, 4, 5, 5, 5, 5, 6, 6, 6, 7, 8, 9,10] Output [5, 5, 5, 5, 3, 3, 3, 6, 6, 6, 2, 2, 4, 4, 1, 7, 8, 9, 10] Helper Description The following structure is used to represent a boundedarray and is already implemented in the default code (Do not write this definition again in your code) typedef struct BoundedArray { int size; int *arr; }boundedarray; 8) The function/method rotateList accepts three arguments as inputs - an integer size, an integer k and a node list_head representing size of the list, the rotation index value and the head node of the linked list, respectively. It is supposed to rotate the linked list in the counterclockwise direction from the kth node The function/method compiles successfully but fails to return the desired result for some test cases. Your task is to fix the code so that it passes all the test cases Note 0<= k <= size Helper Description The following structure is used to represent a node of the linked list and is already implemented in the default code (Do not write this definition again in your code) struct LNode; typedef struct LNodelnode;

struct LNode { int value; struct LNode* next; }; 9) Mr. Jason has captured your friend and has a collar around his neck. He has locked the collar with a given “locking key". Now it can only be opened with an “unlocking key”. Your friend sees the locking key but he does not know how to find the unlocking key. You can calculate the unlocking key if you have the locking key, because the unlocking key will be the smallest (in magnitude) permutation of the digits of the locking key and will never start with zero. Help your friend write an algorithm that outputs the unlocking key by taking key as an input Input The input to the function/method consists of an argument lockingkey, an integer representing the locking key. Output Return an integer representing the unlocking key Constraints -10^7 <= lockingkeys<= 10^7 Note A possibleanswer exists for each input. TestCase 1: Input: 310 Expected Output: 103 TestCase 2: Input: 918 Expected Output: 189 You are required to correct the syntax of the given code without changing its logic. You can click on Compile & 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 main() function as it is not required. Code Approach: For this question. You will need to correct the given implementation. We do not except, you to modify the approach or incorporate any library methods. The function the binary search (inn arr[],int target) of class search performs the binary search algorithm to look for an element target in the input array arr.if the element is found the function returns the index of target arr. If it is not found .the function returns-1 The function seems to work well but goes into an infinite loop for some test cases Your task is to fix the program so that it passes all the test case Note: if there is a time limit exceeded error it can be due to an infinite loop Testcase : Input 54 Expected return value D Testcase : Input 78 Expected return value B

24. You are required to fix all logical errors in the given code. You can click on Compile & Run anytime to check the compilation/execution status of the program. You can use System.Out.println to debug your code. The submitted code should be logically/syntactically correct and pass all test cases. Do not write main() function as it is not required. Code Approach: For this question. You will need to correct the given implementation. We do not except, you to modify the approach or incorporate any library methods. The function/method detectandRemoveLoop accepts an argument – list, a singly linked list of integers. It is supposed to check whether the list contains a loop or not. If a loop is present then it removes the loop by calling another function remove loop. The Function/method detectAndRemoveLoop compiles successfully but fails to return the desired result for the test cases. Your task is to fix the code so that it passes all the test cases. Note: The function/method detectAndRemoveLoop uses other function/method removeLoop that accepts two arguments -loop_node, representing the loop node in the linked list and head, representing the head of the linked list. If a loop exists then there will be only one loop node. Helper Description: The following class is used to represent a node of the linked list and is already implemented in the default code.(Do not write this definition again in your code) Class LLNode { Int value; LLNode next; LLNode() { This.next = null;

} LLNode( int value) { This.value = value; This.next = null; } } Test Case 1: Input: 2 -> 4 -> 3 -> 5 -> 1 ^ <- <- <- <Expected Return Value: 2 -> 4 -> 3 -> 5 -> 1 -> null Test Case 2: Input: -> 2 -> 3 -> 4 ^ <- <- <- <-<- <- <Expected Return Value -> 2 -> 3 -> 4 -> null 25. You are required to fix all logical errors in the given code. You can click on Compile & 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 main() function as it is not required.

Code Approach: For this question. You will need to correct the given implementation. We do not except, you to modify the approach or incorporate any library methods. The function/method stackoperation accepts three arguments-Flag, an integer representing the operation push or pop; stack, a list of integers representing the elements of stack and top, an integer representing the top of the stack. If the flag value is 1, the value is inserted on the top of the stack, and if the flag is value is 2, the topmost element of the stack is deleted. Print a message “Stack Full” if the flag is equal to 1 and the stack is full or else print a message “StackEmpty”, if the flag is equal to 2 and the stack is empty. The function/method compiles successfully but fails to return the desired result for some test cases due to incorrect implementation of functions push and pop. Your task is to fix the code so that it passes all the test cases. Note: The function/method stackOperation uses other functions/methods – Push, which accepts, three arguments – data, an integer representing that has to be inserted at the top of the stack; stack, a list of integers representing the elements of the stack; top, an integer representing the index of the top of the stack for inserting a new element; maxSize, an integer representing the maximum size of the stack. Is-Full, which accepts two integers – top, an integer representing the top of the stack; maxSize, an integer representing the maximum size of the stack. isEmpty, which accepts an integer which checks if the stack is empty or not. printStack, which accepts two arguments – stack, a list of integers representing the elements of stack and top, an integer representing the index of the top of the stack for printing elements of the stack. Pop, which accepts two arguments - stack, a list of integers representing the elements of the stack and top, an integer representing the top of the stack for deleting an element from the top of the stack. The maximum size of the stack is 10.

TestCase :1 Input: 1,[1, 2, 3, 4, 5, 6, 7, 8, 9],9 Expected Returned Value: StackFull TestCase 2: Input: 2, [2, 4, 3, 5], 4 Expected Returned Value: 2435 26. You are required to fix all logical errors in the given code. You can click on Compile & 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 main() function as it is not required. Code Approach: For this question. You will need to correct the given implementation. We do not except, you to modify the approach or incorporate any library methods. The function getArraySum( int *arr, intt len) is supposed to calculate and return the sum of elements of the input array arr of length len (len >=0). The function compiles successfully but fails to return the desired result because of logical errors. Your task is to debug the code so that it passes all the test cases. Assumption You may assume that sum of the elements of the array arr will not exceed the range of its data type.

Test Case 1:

Input: [2, 3, 5, 7, 9], 5 Expected Return value: 26 Test Case 2: Input: [-1,-2, - 3, -4, - 4, -1], 6 Expected Return value: -15

27. You are required to fix all logical errors in the given code. You can click on Compile & 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 main() function as it is not required. Code Approach: For this question. You will need to correct the given implementation. We do not except, you to modify the approach or incorporate any library methods. The function checkGrade(int score) is supposed to return a student’s grade when the student’s test score is passed to it as an argument (0 <= score<=100) Given a particular score, a grade is calculated as per the following table. Score

Grade

Score >=91 76 <= score <=90 61 <= score <= 75

A B C

Score <=60

D

The function compiles successfully but fails to return the desired result because of logical errors. Your task is to debug the code so that it passes all the test cases. Test Case 1: Input: 54 Expected Return value: D Test Case 2: Input: 78 Expected Return value: B 28. You are required to complete the given code by reusing existing functions. You can click on Compile & 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 main() function as it is not required. Code Approach: For this question. You will need to correct the given implementation. We do not except, you to modify the approach or incorporate any library methods. The function calculateGeneralLCM(int *arr, int len) accepts an integer array arr of length len. It is supposed to calculate and return the LCM of elements in the input array.

Another function calculateLCM(int a, int b) returns the LCM of two input numbers a and b. Your task is to use the calculateLCM(int a, int b) function to complete the code in calculateGeneralLCM(int *arr, int len) so that it passes all test cases. Test Case 1: Input: [3, 2, 45, 6, 5, 65280, 4, 3, 46], 9 Expected Return Value: 53820 Test Case 2: Input: [2, 6, 3, 5, 6, 9, 3, 7, 4, 6, 7], 11 Expected Returned Value: 360 30. You are required to correct the syntax of the given code without changing its logic. You can click on Compile & 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 main() function as it is not required. Code Approach: For this question. You will need to correct the given implementation. We do not except, you to modify the approach or incorporate any library methods. The function checkGreatestFactor(int num) accepts an integer num as an input and is supposed to return the highest Factor that is less than num. It uses another function calculateFactor(int inputNumber) for calculating the factors of a number.

The function checkGreatestFactor looks fine but gives a compilation error. Your task is to debug the code so that it passes all the test cases. Test Case 1: Input: 234 Expected Return Value: 117 Test Case 2: Input: 89 Expected Return Value: 1 31. The current selected programming language is Java. We emphasize the submission of a fully working code over partially correct but efficient code. Once submitted, You cannot review this problem again. You can use System.out.println() to debug your code. The System.out.println() may not work In case of syntax/runtime error. The version of JDK being used is 1.8. Systems that can run multiple concurrent jobs on a single CPU have a process for choosing which tasks to run when, and how to break them up, called “scheduling”. The Round-Robin policy for scheduling runs each job for a fixed amount of time before switching to the next job. The waiting time for a job is the total time that it spends waiting to be run. Each job arrives at a particular time for scheduling and takes a certain amount of time to run. When a new job arrives, it is scheduled after existing jobs already wating for CPU time. Given a list of job submissions, calculate the average waiting time for all jobs using the Round Robin policy. The input to the method waitingTimeRobin of class RoundRobin consists of two integer arrays containing job arrival and run times and

an integer q representing the fixed amount of time used by the RoundRobin policy. The list of job arrival times and job run times are sorted in ascending order by arrival time. For jobs arriving at the same time, process them in the order they are found in the arrival array. You can assume the jobs arrive in such a way the CPU is never idle. The function should return a floating point number for the average waiting time which is calculated using Round-Robin policy. Assume 0 <= job arrival time <00 and 0 < job run time < 100. Test Case 1: Input: [0, 1, 4], [5, 2, 3], 3 Excepted Return Value: 2.3333333 Explanation: The process run in the following time slots- P1 initially runs for 3 seconds, P2 runs for 2 second, meanwhile P3 arrives. Since P1 was in the queue first, it runs for its remaining 2 seconds while P3 waits. Then P3 finally runs for 3 secs. The waiting time of processes P1, P2, P3 are 2, 2 and 3 respectively. The average is thus 2.3333333 second. Test Case 2: Input: [0, 1, 3, 9], [2, 1, 7, 5], 2 Expected Return Value: 1.0 Explanation: The processes run in the following time slots – P1 initially runs for 2 seconds. P2 runs for second, P3 runs for 6 seconds till P4 enters the system at the 9th second – when it runs for 2 seconds, P3 then runs for 1 second followed by P4 running for 3 seconds. The waiting time of

processes P1, P2, P3, P4 are 0, 1, 2, 1 respectively. The average is thus 1 second.

41. You are required to fix all logical errors in the given code. You can click on Compile & Run anytime to check the compilation/execution status of the program. You can use System.Out.println to debug your code. The submitted code should be logically/syntactically correct and pass all test cases. Do not write main() function as it is not required. Code Approach: For this question. You will need to correct the given implementation. We do not except, you to modify the approach or incorporate any library methods. The function/method mergelists accepts two arguments – list1 and list2, representing two singly linked lists whose elements are sorted in ascending order of their values. This function is supposed to return a linked list formed by merging list and list2 such that the linked list remains sorted. The function compiles successfully but fails to return the desired result for some test cases. Your task is to fix the code so that it passes all the test cases. Test Case 1: Input: -> 2 -> 3 -> 4 -> null, 1 -> 3 -> 5 -> 7 -> null Expected Return Value: -> 1 -> 2 -> 3 -> 3 -> 4 -> 5 -> 7 -> null TestCase 2: Input: 2 -> 3-> 6-> 7 -> 12 -> null, 1 -> 4 -> 5 -> 8 -> 9 -> null Expected Return value: -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 -> 9 -> 12 -> null

42. You are required to fix all logical errors in the given code. You can click on Compile & Run anytime to check the compilation/execution status of the program. You can use System.out.println to debug your code. The submitted code should be logically/syntactically correct and pass all test cases. Do not write main() function as it is not required. Code Approach: For this question. You will need to correct the given implementation. We do not except, you to modify the approach or incorporate any additional library methods. A binary search tree (BST) is defined as a binary tree in which each node satisfies the property such that its value is larger than the value of every node in its left subtree, and less than or equal to the value of every node in its right subtree. The distance between two values in a binary search tree is the minimum number of edges traversed to reach from one value to the other. The function/method is BST accepts an argument root1, representing the root of a tree it returns 1 if the tree is BST, else returns 0. The Function/method compiles successfully but fails to return the desired result for the test cases. Your task is to fix the code so that it passes all the test cases. Helper Description: The following class is used to represent a node of the tree and is already implemented in the default code. (Do not write this definition again in your code) Class TreeNode { Int value; TreeNode left, right; TreeNode ( int value) { This. Value = value; Left = null;

Right = null; } } Test Case 1: Input: 3 2

3

Expected Return Value: 1 Test Case 2: Input: 10 24 4

8

12

Expected Return Value: 0 43. You are required to fix all logical errors in the given code. You can click on Compile & 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 main() function as it is not required. Code Approach: For this question. You will need to correct the given implementation. We do not except, you to modify the approach or incorporate any additional library methods. A binary search tree (BST) is defined as a binary tree in which each node satisfies the property such that its value is larger than the value of every node in its left subtree, and less than or equal to the value of every node in its right subtree. The distance between two values in a

binary search tree is the minimum number of edges traversed to reach from one value to the other. The function/method is SubBST accepts two inputs arguments – bRoot1 and bRoot, representing the root of the first tree and the root of the second tree it returns 1 if the tree with root bRoot2 is a sutree of a tree with root bRoot1, else it returns 0. The Function/method compiles successfully but fails to return the desired result for the test cases. Your task is to fix the code so that it passes all the test cases. Note: The function/method isSubBST uses another function/method – areIdentical, which accepts two root nodes, bst1 and bst2, to check if these two binary search trees are identical or not. Helper Description: The following structure is used to represent a node of the tree and is already implemented in the default code. (Do not write this definition again in your code) Struct TNode; Typedef struct TNode tnode; Struct TNode{ Tnode * left; Tnode* right; Int value; }; Test case 1 is not clear Test Case 2: Input: [ 5

3 2

7 4

6

8

],[ 5 3

7

] Expected Returned Value: 0 Explanation: Partial sub trees do not count. 44. You are required to fix all logical errors in the given code. You can click on Compile & Run anytime to check the compilation/execution status of the program. You can use System.out.println to debug your code. The submitted code should be logically/syntactically correct and pass all test cases. Do not write main() function as it is not required. Code Approach: For this question. You will need to correct the given implementation. We do not except, you to modify the approach or incorporate any library methods. The function getArraySum( int arr[]) of class ArraySum is supposed to calculate and return the sum of elements of the input array arr. The function compiles successfully but fails to return the desired result because of logical errors. Your task is to debug the code so that it passes all the test cases. Assumption You may assume that sum of the elements of the array arr will not exceed the range of its data type. Test Case 1: Input:

[2, 3, 5, 7, 9] Expected Return Value: 26 TestCase 2: Input: [-1, -2, -3, -4, -4, -1] Expected return Value: -15 45. You are required to fix all logical errors in the given code. You can click on Compile & 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 main() function as it is not required. Code Approach: For this question. You will need to correct the given implementation. We do not except, you to modify the approach or incorporate any library methods. The function printTable(int num) is supposed to print the first ten multiples of the multiplication table of the input number num. The function compiles fine but fails to return the desired result for some test cases. Your task is to debug the code so that it passes all the test cases. Test Case 1: Input: 6 Expected Return Value; 6 12 18 24 30 36 42 48 54 60 Test Case 2: Input:

0 Expected Return Value: 0000000000 46. You are required to complete the given code by reusing existing functions. You can click on Compile & Run anytime to check the compilation/execution status of the program. You can use System.out.println to debug your code. The submitted code should be logically/syntactically correct and pass all test cases. Do not write main() function as it is not required. Code Approach: For this question. You will need to correct the given implementation. We do not except, you to modify the approach or incorporate any library methods. The function calculateGeneralLCM(int GeneralizedLCM accepts an integer array arr.

arr[])

of

class

It is supposed to calculate and return the LCM of elements in the input array. Another function calculateLCM(int a, int b) returns the LCM of two input numbers a and b. Your task is to use the calculateLCM(int a, int b) function to complete the code in calculateGeneralLCM(int arr[]) so that it passes all test cases. Test Case 1: Input: [3, 2, 45, 6, 5, 0, 4, 3, 46], 9 Expected Return Value: 53820 Test Case 2: Input: [2, 6, 3, 5, 6, 9, 3, 7, 4, 6, 7], 11 Expected Returned Value:

360

47. You are required to complete the given code by reusing existing functions. Click on Helper Code tab to find out the details of functions/ classes provided for reuse. You can click on Compile & 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 main() function as it is not required. Code Approach: For this question. You will need to correct the given implementation. We do not except, you to modify the approach or incorporate any library methods. 48. You are given a predefined structure PalindromeCollection and also the collection of related functions that can be used to perform some basic operations on the structure. You must implement the function printPallindrome(int num, int n) to accept the initial number num and number of digits n as inputs and prints all the palindrome numbers of n digits starting from the initial number num. Use the PallindromeCollection structure and the associated functions for this task. (Please refer to the helper code tab for details regarding the structure PallindromeCollection and the predefined functions around it). Test Case 1: Input: 792, 3 Expected Return Value: [797, 808, 818, 828, 838, 848, 858, 868, 878, 888, 898,909,919, 929, 939, 949, 959, 969, 979, 989, 999] Test Case 2: Input:

892, 3 Expected Return Value: [ 898,909,919, 929, 939, 949, 959, 969, 979, 989, 999]

49. The current selected programming language is Java. We emphasize the submission of a fully working code over partially correct but efficient code. Once submitted, You cannot review this problem again. You can use System.out.println() to debug your code. The System.out.println() may not work In case of syntax/runtime error. The version of JDK being used is 1.8. Write a method to insert an integer into a circular linked –list whose elements are sorted in ascending order [smallest to largest] The input to the method insertedSortedList of class SortedList is an object of the class CNode and an integer n between 0 and 100. The method should return an object of the class CNode containing information of newly inserted node. The following class is used to represent a node of the circular linked list and is already implemented in the default code.(Do not write this definition again in your code.) Public Class CNode { Public int value: Public CNode next; } Test Case 1: Input : [3 -> 4 -> 6 -> 1 -> 2 -> ^],5 Excepted Return Value:

[5 -> 6 -> 1 -> 2 -> 3 -> 4 -> ^] Test Case 2: Input : [1 -> 2 -> 3 -> 4 -> 5 -> ^],0 Excepted Return Value: [0 -> 1 -> 2 -> 3 -> 4 -> 5 -> ^] 50. The current selected programming language is C. We emphasize the submission of a fully working code over partially correct but efficient code. Once submitted, You cannot review this problem again. You can use printf() to debug your code. The printf() may not work In case of syntax/runtime error. The version of GCC being used is 5.2.0. THE Least-Recently-Used(LRU) cache algorithm evicts the element from the cache(when it’s full) that was least-recently-used. After an element is requested from the cache, it should be added to the cache(if not already there) and considered the most- recently- used element in the cache. Given the maximum size of the cache and a list of integers (to request from the cache), calculate the number of cache misses using the LRU cache algorithm. A cache miss occurs when the requested integer does not exist in the cache. Initially, the cache is empty. The input to the function IruCountMiss shall consist of an integer max_cache_size, an array pages and its length len. The function should return an integer for the number of cache misses using the LRU cache algorithm. Assume that the array pages always has pages numbered from 1 to 50. Test Case 1: Input: 3, [7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0], 16

Expected return value: 11 Test Case 2: Input: 2, [2, 3, 1, 3, 2, 1, 4, 3, 2], 9 Expected return value: 8 Explanation: The following page numbers are missed one after the other -2, 3, 1, 2, 1, 4, 3, 2. This results in 8 page misses.

12.You are required to fix all logical errors in the given code.You can click on Compile & 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 the test cases .Do not write main () function as it 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 libraries. The function/method reverseLinkedList accepts one argument- list, representing the head of a singly linked list and is supposed to reverse the second half of the linked list. For example, if the list is 2->3->6->1->4->8->9->7 The function/method compiles successfully but fails to return the desired output due to incorrect implementation of linked lists.Your task is to fix the code so that it passes all the test cases. Note: If the number of elements in the list(N) is odd, then the second half of the list begins at position (N+1)/2.

If the number of elements in the list(N) is even, then the second half of the list begins at position (N/2)+1. 13.The current selected programming language is C. We emphasize the submission of a fully working code over partially correct but efficient code. Once submitted, you cannot review this problem again. You can use printf() to debug your code. The printf() may not work in a case of syntax/runtime error. The version of GCC being used is 5.2.0. A sequence of parenthesis is called balanced if it consists entirely of pairs of opening/closing parenthises(in that order),which is well nested, For example, sequences “(())()”,”()” and “(()(()))” are balanced , while “(()” and “(())(“ are not. Write the function to determine if a given string contains balanced sequence of paranthesis. The inputs to the function balancedParantheses is a string str. Each character in the string will be “(“ or “)”. The output is the count of balanced pairs if the sequence is balanced or -1 otherwise. For example, if the input sequence is “(()((())”, the expected output is 4. You are required to fix all logical errors in the given code. You can click on Compile & Run anytime to check the compilation/execution status of the program. You can use System.Out.println to debug your code. The submitted code should be logically/syntactically correct and pass all test cases. Do not write main() function as it is not required. Code Approach: For this question. You will need to correct the given implementation. We do not except, you to modify the approach or incorporate any additional library methods. The function/method detectandRemoveLoop accepts an argument – list, a singly linked list of integers. It is supposed to check whether the list contains a loop or not. If a loop is present then it removes the loop by calling another function remove loop. The Function/method detectAndRemoveLoop compiles successfully but fails to return the desired result for the test cases. Your task is to fix the code so that it passes all the test cases. Note:

The function/method function/method

detectAndRemoveLoop

uses

other

removeLoop that accepts two arguments -loop_node, representing the loop node in the linked list and head, representing the head of the linked list. If a loop exists then there will be only one loop node. You are required to fix all logical errors in the given code. You can click on Compile & 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 main() function as it is not required. Code Approach: For this question. You will need to correct the given implementation. We do not except, you to modify the approach or incorporate any library methods. The function/method stackOperation accepts three arguments-Flag, an integer representing the operation push or pop; stack, a list of integers representing the elements of stack and top, an integer representing the top of the stack. If the flag value is 1, the value is inserted on the top of the stack, and if the flag is value is 2, the topmost element of the stack is deleted. Print a message “Stack Full” if the flag is equal to 1 and the stack is full or else print a message “StackEmpty”, if the flag is equal to 2 and the stack is empty. The function/method compiles successfully but fails to return the desired result for some test cases due to incorrect implementation of functions push and/or pop. Your task is to fix the code so that it passes all the test cases. Note: The function/method stackOperation uses other functions/methods – Push, which accepts, three arguments – data, an integer representing the element that has to be inserted at the top of the stack; stack, a list of integers representing the elements of the stack; top, an integer representing the index of the top of the stack for inserting a new element; maxSize, an integer representing the maximum size of the stack.

Is-Full, which accepts two integers – top, an integer representing the top of the stack; maxSize, an integer representing the maximum size of the stack. isEmpty, which accepts an integer which checks if the stack is empty or not. printStack, which accepts two arguments – stack, a list of integers representing the elements of stack and top, an integer representing the index of the top of the stack for printing elements of the stack. Pop, which accepts two arguments - stack, a list of integers representing the elements of the stack and top, an integer representing the top of the stack for deleting an element from the top of the stack. The maximum size of the stack is 10. You are required to fix all logical errors in the given code. You can click on Compile & 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 main() function as it is not required. Code Approach: For this question. You will need to correct the given implementation. We do not except, you to modify the approach or incorporate any additional library methods. The function getArraySum( int *arr, intt len) is supposed to calculate and return the sum of elements of the input array arr of length len (len >=0). The function compiles successfully but fails to return the desired result because of logical errors. Your task is to debug the code so that it passes all the test cases. Assumption You may assume that sum of the elements of the array arr will not exceed the range of its data type. You are required to fix all logical errors in the given code. You can click on Compile & 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 main() function as it is not required. Code Approach: For this question. You will need to correct the given implementation. We do not except, you to modify the approach or incorporate any additional library methods. The function checkGrade(int score) is supposed to return a student’s grade when the student’s test score is passed to it as an argument (0 <= score<=100) Given a particular score, a grade is calculated as per the following table. Score

Grade

Score >=91 76 <= score <=90

A B

61 <= score <= 75

C

Score <=60

D

The function compiles successfully but fails to return the desired result because of logical errors. Your task is to debug the code so that it passes all the test cases. You are required to complete the given code by reusing existing functions. You can click on Compile & 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 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 except, you to modify the approach or incorporate any library methods. The function calculateGeneralLCM(int *arr, int len) accepts an integer array arr of length len.

It is supposed to calculate and return the LCM of elements in the input array. Another function calculateLCM(int a, int b) returns the LCM of two input numbers a and b. Your task is to use the calculateLCM(int a, int b) function to complete the code in calculateGeneralLCM(int *arr, int len) so that it passes all test cases. You are required to correct the syntax of the given code without changing its logic. You can click on Compile & 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 main() function as it is not required. Code Approach: For this question. You will need to correct the given implementation. We do not except, you to modify the approach or incorporate any library methods. The function checkGreatestFactor(int num) accepts an integer num as an input and is supposed to return the highest Factor that is less than num. It uses another function calculateFactor(int inputNumber) for calculating the factors of a number. The function checkGreatestFactor looks fine but gives a compilation error. Your task is to debug the code so that it passes all the test cases. The current selected programming language is Java. We emphasize the submission of a fully working code over partially correct but efficient code. Once submitted, You cannot review this problem again. You can use System.out.println() to debug your code. The System.out.println() may not work In case of syntax/runtime error. The version of JDK being used is 1.8. Systems that can run multiple concurrent jobs on a single CPU have a process for choosing which tasks to run when, and how to break them up, called “scheduling”. The Round-Robin policy for scheduling runs each job for a fixed amount of time before switching to the next job.

The waiting time for a job is the total time that it spends waiting to be run. Each job arrives at a particular time for scheduling and takes a certain amount of time to run. When a new job arrives, it is scheduled after existing jobs already waiting for CPU time. Given a list of job submissions, calculate the average waiting time for all jobs using the Round Robin policy. The input to the method waitingTimeRobin of class RoundRobin consists of two integer arrays containing job arrival and run times and an integer q representing the fixed amount of time used by the RoundRobin policy. The list of job arrival times and job run times are sorted in ascending order by arrival time. For jobs arriving at the same time, process them in the order they are found in the arrival array. You can assume the jobs arrive in such a way the CPU is never idle. The function should return a floating point number for the average waiting time which is calculated using Round-Robin policy. Assume 0 <= job arrival time <00 and 0 < job run time < 100. The current selected programming language is Java. We emphasize the submission of a fully working code over partially correct but efficient code. Once submitted, You cannot review this problem again. The version of JDK being used is 1.8. There is a colony of 8 cells arranged in a straight line where each day every cell competes with its adjacent cells(neighbours). Each day, for each cell, if its neighbours are both active or inactive. The cell becomes inactive the next day, otherwise it becomes active the next day. Assumptions The two cells on the ends have single adjacent cell, so the other adjacent cell can be assumed to be always inactive. Even after updating the cell state, consider its previous state for updating the state of other cells. Update the cell information of all cells simultaneously. Write a method cellComplete of class Colony which takes an 8 element array of integers cells representing the current state of 8 cells and an integer days representing the number of days to simulate. The

function should return an array representing the state of the cells after the given number of days. An integers value of represents an active cell and value of 0 represents an inactive cell. You are required to fix all logical errors in the given code. You can click on Compile & Run anytime to check the compilation/execution status of the program. You can use System.out.println to debug your code. The submitted code should be logically/syntactically correct and pass all test cases. Do not write main() function as it is not required. Code Approach: For this question. You will need to correct the given implementation. We do not except, you to modify the approach or incorporate any additional library methods. A binary search tree (BST) is defined as a binary tree in which each node satisfies the property such that its value is larger than the value of every node in its left subtree, and less than or equal to the value of every node in its right subtree. The distance between two values in a binary search tree is the minimum number of edges traversed to reach from one value to the other. The function/method isBST accepts an argument root1, representing the root of a tree it returns 1 if the tree is BST, else returns 0. The Function/method compiles successfully but fails to return the desired result for the test cases. Your task is to fix the code so that it passes all the test cases.

The current selected programming language is Java. We emphasize the submission of a fully working code over partially correct but efficient code. Once submitted, You cannot review this problem again. You can use System.out.println () to debug your code. The System.out.println() may not work in case of syntax/runtime error.The version of JDK being used is 1.8. A sequence of parenthesis is called balanced, if it consists entirely of pairs of opening/ closing parenthesis(in that order) which is well nested. For example, sequence “(())()”,”()” and “(()(()))” are balanced while “(()” and “((()))(“ are not.

Write a method to determine if a given string contains balanced sequence of parenthesis. The input to the method balanced parenthesis of classes. Parenthesis is a string str.for each character in the string will be “(“or “)”. The output is the count of balanced pairs if the sequence is balanced or -1 otherwise. For example, if the input sequence is “(()(()))”, the expected output is 4. Test Case 1: Input: -> 2 -> 3 -> 4 -> null Expected Return Value -> 2 -> 4 -> 3 -> null

Test Case 2: Input: 11 -> 23 -> 16 ->9 ->21 -> null Expected Return Value 11 -> 23 ->21 ->9 -> 16 -> null Explanation: The length of the output linked list is 5 So, the middle element is the one at (5+1)/2 = 3rd position. You are required to correct the syntax of the given code without changing its logic.You can click on Compile & 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 main() function as it is not required. Code Approach: For this question. You will need to correct the given implementation. We do not except, you to modify the approach or incorporate any library methods.

The function getDigitSum( intarr[]) of class DigitSum accepts an integer array arr. It is supposed to calculate the sum of digits of the smallest element in the input array, it returns 1, if the calculated sum is even, otherwise it returns 0. However there is a compilation error in the code. Your task is to fix it so that it program works for all inputs Note: The function getDigitSum uses another function getSum(int num)that returns the sumof digits of the input number num. Test case 1: Input: [91,92,-131,80,40] Expected Return Value: 0 Test case 2: Input: [23,18,11,3] Expected Return Value: 0

You are required to complete the given code by reusing existing functions. Click on Helper Code tab to find out the details of functions/ classes provided for reuse.You can click on Compile & 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 main() function as it is not required. Code Approach: For this question. You will need to correct the given implementation. We do not except, you to modify the approach or incorporate any library methods.

You are given a predefined structure PrimeBankstructure and also the collection of related functions that can be used to perform some basic operations on the structure. You must implement the function printPrime(int num, int digit) to accept the initial number num and number of digits n as inputs and prints all the prime numbers of n digits starting from the initial number num. Use the Primebankstructure and the associated functions for this task. (Please refer to the helper code tab for details regarding the structure PrimeBankand the predefined functions around it). Test Case 1: Input: 891, 3 Expected Return Value [907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997] Test Case 2: Input: 921, 3 Expected Return Value [929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997] You are required to complete the given code by reusing existing functions. Click on Helper Code tab to find out the details of functions/ classes provided for reuse.You can click on Compile & Run anytime to check the compilation/execution status of the program. You can use System.out.println to debug your code. The submitted code should be logically/syntactically correct and pass all test cases. Do not write main() function as it is not required. Code Approach: For this question. You will need to correct the given implementation. We do not except, you to modify the approach or incorporate any library methods.

The function findMinElement( intarr[], int arr2 []) of class MinArray accepts two intger arrays arr1, arr2. It is supposed to return the sallest element in both the input arrays. Another function sortArray( intarr]) sorts in the input array arr of length len in ascending order returns it. Your task is to use the SortArray( intarr[]) function to complete code in findMinElement(int arr1[], int arr2[]), so that it passes all the test case. Test case 1: Input: [2,5,1,3,9,8,4,6,5,2,3,11],[11,13,3,4,15,17,67,44,2,100,23] Excepted Return Value: 1 Test case 2: Input: [100,22,43,912,56,89,85,234,123,456,234,890,101] Excepted Return Value: 22 You are required to fix all logical errors in the given code. You can click on Compile & Run anytime to check the compilation/execution status of the program. You can use System.out.println to debug your code. The submitted code should be logically/syntactically correct and pass all test cases. Do not write main() function as it is not required. Code Approach: For this question. You will need to correct the given implementation. We do not except, you to modify the approach or incorporate any additional library methods. The function deleteDupicate(int arr[]) of class DistinctArray takes an array arr as an input. It is supposed to remove duplicate integer from the input array arr such that for each distinct te first occurrence is retained and all the duplicate elements following it or removed, For

example, given the input array arr2,3,2,2,5,6,6,7] the expected output is [2,3,5,6,7]. The function compiles successfully but fails to return the desired result because of logical error. Your task is to debug the program so that it passes all the test cases. Test case 1: Input: [2,2,3,3,4,,4] Excepted Return Value: [2,3,4] Test case 2: Input: [21,21,21,21,21] Excepted Return Value: [21]

Code Approach: for this question you will need to correct the given implementation, We do not except you to modifythe approach or incorporate any additional library methods. A ternary search tree is defined as a ternary tree in which a search, proceed character by character, compares the current character In the search string with the character at the current node. If the search character is lexicographically smaller, the search goes to the left child but if the search character is lexicographically larger, the search goes to the right child. When the search character is equal , the search goes to the middle child and proceeds to the next character in the search string. For example, ternary search tree for strings CUP,CAT,CD,CUT C

U

A

P

T D

T

The function/method insertIntoTernaryTree accepts the arguments – tree, representing a ternary tree and input str, a string representing the word to be inserted in the ternary tree and ptr, an integer representing the index of the current character in the inputStr. The function/method is supposed to return the ternary tree node after inserting the word into the tree. The function/ method compiles successfully but fails to return the desired result for some test cases. Your task is to fix the code so that it passes all the test cases. Input:

C

B

A

u

t

a g

u

p

t [c, a, t, s], 0 Expected Return Value: C

B

A

u

t

a g

u

p

t

s You are required to fix all logical errors in the given code. You can click on Compile & Run anytime to check the compilation/execution status of the program. You can use System.out.println to debug your code. The submitted code should be logically/syntactically correct and pass all test cases. Do not write main() function as it is not required. Code Approach: For this question. You will need to correct the given implementation. We do not except, you to modify the approach or incorporate any additional library methods. The functionprintColor[int num] of class Color is supposed to print names of colors according to the given input number num. For example, if the values of num equal 1, 2, 3, 4 the function prints “Red”, “Black”, “White”, “Green”, respectively for any other values of num, It should print “No color”. The function compiles fine but fails to return the desired result for some test cases.

Your task is to fix the code so that it passes all the test cases. 1.Thecurrent selected programming language is Java. We emphasize the submission of a fully working code over partially correct but efficient code. Once submitted, you cannot review this problem again. You can use System.out.println() to debug your code. The System.out.println() may not work in case of syntax/runtime error. The version of JDK being used is 1.8. Systems that can run multiple concurrent job on a single CPU have a process for choosing which tasks to run when and how to break them up, called “scheduling”. The Round-Robin policy for scheduling runs each job for a fixed amount of time before switching to the next job. The waiting time for a job is the total time that it spends waiting to be run. Each job arrives at particular time for scheduling and tasks a certain amount of time to run. When a new job arrives, it is scheduled after existing jobs already waiting for CPU time. Given a list of job submissions calculate the average waiting time for all jobs using the Round-Robin policy. The input to the method waitingTimeRobin of class RoundRobin consists of two integer arrays containing job arrival and run times and an integer q representing the fixed amount of time used by the RoundRobin policy .The list of job arrival times and job run times are sorted in ascending order by arrival time. For jobs arriving at the same time process them in the order they are found in the arrival array. You can assume the jobs arrive in such a way that the CPU is idle.

2.A binary search tree (BST) is defined as a binary tree in which each node satisfies the property such that its value is larger than the value of every node in its left subtree and less than or equal to the value of every node in its right subtree. The distance between two values in a binary search tree is the minimum number of edges traversed to reach from one value to the other. The function isBST accepts an argument root1, representing the root of a tree it returns 1 if the tree is BST else returns 0.

The function/method compiles successfully but fails to return the desired result for some test cases. Your task is to fix the code so that it passes all the test cases. HELPER DESCRIPTION The following class is used to represent a node of the tree and is already implemented in the default node (Do not write the definition again in your code): Class TreeNode { int value; TreeNodeleft , right; TreeNode(int value) { this.value=value; left=null; right=null; } 3.The function printTable(intnum) is supposed to print the first ten multiples of the multiplication table of the input number num. The function compiles fine but fails to return the desired result for some test cases. Your task is to fix the program so that it passes all the test cases.

4.The function /method rotateList accepts three arguments as inputs – an integer size an integer k and a node list_head representing size of the list, the rotation index value and the head node of the linked list respectively. It is supposed to rotate the linked list in the counter clockwise direction from the kth node.

The function/method compiles successfully but fails to return the desired result for some test cases. Your task is to fix the program so that it passes all the test cases. NOTE 0<=k<=size HELPER DESCRIPTION The following structure is used to represent a node of the linked list and is already implemented in the default code. Struct LNode;

5.The function /method PrintSortedList accepts two arguments – a node list-head representing the head node of the sorted linked list in an integer num, representing the value that has to be inserted in the linked list such that the linked list remains sorted. This function then prints the elements from the linked list. The function /method compiles successfully but fails to return the desired result for some test cases due to incorrect implementation of the function sortedInsert. Your task is to fix the code so that it passes all the test cases. NOTE The function /method PrintSortedList uses another function/methodsortedinsert, Which accepts a head node head _ref,and an integer num to be inserted in the linked list.

6.The function/method mergeLists accepts two arguments –list1 and list2, representing two singly linked list whose elements are sorted in ascending order of their values. This function is supposed to return a linked list formed by merging list1 and list2 such that the linked list remains sorted. The function /method compiles successfully but fails to return the desired result for some test cases. Your task is to fix the code so that it passes all the test cases.

HELPER DESCRIPTION The following structure/method is used to represent a node to represent a node of the linked list and is already implemented in the default code Struct LNode { int value; lnode*next; };

The function/method insertSortedCircularList accepts two arguments – clist representing the head of the circular linked list whose elements are sorted in ascending order and val, an integer representing the value to be inserted. This function is supposed to insert val to the circular list represented by the cList in such a manner that cList remains sorted. The function insertSortedCircularList uses another function printList that accepts one argument- cList the head of a circular linked list and prints its elements. The function /method compiles successfully but fails to return the desired result for some test cases. Your task is to fix the code so that it passes all the test cases. HELPER DESCRIPTION The following structure represents a circular linked list node and is already implemented in the default code structCNode; typedefstructCNodecnode; structCNode { int value; cnode* next;

};

8.The function printPattern(intnum) prints even or odd numbers based on the value of the input argument num(num>=0). If the input number num is even the function is expected to print the first num even whole numbers and in case it is odd is expected to print the first num odd numbers. For ex. Given input 2 the function prints the string “0 2”(without quotes).

The function /method compiles successfully but fails to return the desired result for due to logical errors. Your task is to fix the code so that it passes all the test cases.

9.You are given a predefined class PrimeBank and also a collection of related functions that can be used to perform some basic operations on the class. You must implement the function printPrime(intnum, int digit) to accept the initial number num and number of digits n as inputs and prints all the prime numbers of n digits starting from the initial number num. Use the PrimeBank class and the associated functions for this task. TESTCASE 1: Input: 891, 3 Expected Return Value: [907,911,919,929,937,941,947,953,967,971,977,983,991,997]

TESTCASE 2:

Input: 921, 3 Expected Return Value: [929,937,941,947,953,967,971,977,983,991,997]

10.Mooshak the mouse has been placed in a maze. There is a huge chunk of cheese somewhere in the maze. The maze is represented as a two dimensional array of integers, where 0 represents walks, 1 represents paths where Mooshak can move and 9 represents the huge chunk of cheese. Mooshak starts in the top left corner at 0, 0. Write a function isPath to determine if Mooshak can reach the huge chunk of cheese. The inputs to isPath consist of a two dimensional array grid representing the maze matrix and dimensions m, n of the matrix. The function should return 1 if there is a path from Mooshak to the cheese and 0 if not. Mooshak is not allowed to leave the maze or climb on walls. Example 8x8 maze where Mooshak can get the cheese. 10111001 10001111 10000000 10109011 11101001 10101101 10000101 11111111

1)

The function/methoddetectAndRemoveLoop accepts an argument list, a singly linked list of integers.It is supposed to check whether the list contains a loop or not. If a loop is present then it removes the loop by calling another function removeLoop. The function/methoddetectAndRemoveLoop compiles successfully but fails to return the desired result for the test cases. Your task is to fix the code so that it passes all the test cases. Note The function/methoddetectAndRemoveLoop uses other function/method removeLoopthat accepts two arguments - loop_node, representing the loop node in the linked list and head, representing the head of the linked list. If a loop exists then there will be only one loop node. Helper Description The following class is used to represent a node of the linked list and is already implemented in the default code (Do not write this definition again in your code) Class LLNode { int value; LLNode next; LLNode() { this.next = null; } LLNode(int value) { this.value = value; this.next = null; } } 2) The function/method PrintSortedList accepts two arguments - a node list_head representing the head node of the sorted linked-list and an integer num, representing the value that has to be inserted in the linked-list such that the linked list remains sorted. This function then prints the elements from the linked-list. The function/method compiles successfully but fails to return the desired result for same test cases due to incorrect implementation of the function sortedlnsert. your task is to fix the code so that it passes all the test cases. Note:

The function/method PrintSortedList uses another function/method sortedInsert, which accepts a head node head_ref, and an integer num to be inserted in the linked-list. Helper Description The following structure is used to represent a node of the linked list and is already implemented in the default code. (Do not write this definition again in your code): struct LNode; typedef struct LNodelnode; struct LNode { int value; lnode* next; }; TestCase 1: Input: [1->2->3->4->5-> NULL],2 Expected Output: 22345 TestCase 2: Input: [2->3->6->4->5-> NULL],7 Expected Ouput: 236457 3) A ternary search tree is defined as a ternary tree in which a search, proceed character by character, compares the current character in the search string with the character at the current node. If the search character is lexicographically smaller, the search goes to the left child but if the search character is lexicographically larger, the search goes to the right child. When the search character is equal, the search goes to the middle child and proceeds to the next character in the search string. For example, ternary search tree for strings CUP, CAT, CD,CUT C U AP TDT The function/methodinsertIntoTernaryTree accepts three arguments tree, representing a ternary tree, inputStr, a string representing the

word to be inserted in the ternary tree and ptr, an integer representing the index of the current character in InputStr. The function/method is supposed to return the ternary tree node after inserting the word into the tree. The function/method compiles successfully but fails to return the desired result for same test cases due to incorrect implementation of the function. your task is to fix the code so that it passes all the test cases.

4) The function/method levelOrderNAry accepts an argument – tree, representing an N-ary tree The function/method is supposed to print the nodes in a level-order traversal. The function/method compiles successfully but fails to return the desired result for some/all test cases. Your task is to fix the code so that it passes all the test cases. Note: The maximum number of child a node can have is 50. Helper Description The following structure is used to represent a node of the n-ary tree and is already implemented in the default code (Do not write this definition again in your code) struct NAryNode; typedef struct NAryNodeNANode; struct NAryNode { char key; NANode* child[50]; int childsize; }; TestCase 1: Input: [ 0

1

2

3

4 5 6 7 8 9 10 11 12 ]

Expected Output: 0 1 2 3 4 5 6 7 8 9 10 11 12 TestCase 2: Input: [ 10

11

12

3

2 1 13 ] Expected Output: 10 11 12 3 2 1 13 5) The functiorcheckGreatestFactor(int num)of class GreatestFactor accepts an integer num as an input and is supposed to return the highest factor that is less than num It uses another function calculateFactor(int inputNumber)for calculating the factors of a number. The function checkGreatestFactor looks fine but gives a compilation error. Your task is to fix the program so that it passes all the test cases

6) The function checkGrade(int marks) is supposed to return a student's grade when the student's test marks is passed to it as an argument (0<= marks <=100). Given a particular marks, a grade is calculated as per the following table: Score Grade marks >= 91 A 76 <= marks <= 90 B 61<= marks <= 75C marks <= 60 D The function compiles successfully but fails to return the desired result due to logical errors. Your task is to debug the program to pass all the test cases.

7) The function binarySearch(int arr[], int target) of class Search performs the binary search algorithm to look for an element target in the input array arr. If the element is found, the function returns the index of target in arr. If it is not found, the function returns -1. The function seems to work well but goes into an infinite loop for some test cases. Your task is to fix the program so that it passes all the test cases. Note: If there is Time Limit Exceeded error, can be due to an infinite loop.

8) The function calculateGeneralLCM(int arr[])of class GeneralizedLCM accepts an integer array arr. It is supposed to calculate and return the LCM of elements in the input array. Another function calculateLCM(int a,int b) returns the LCM of two input numbers a and b. Your task is to use the calculateLCM(int a,int b) function to complete the code in calculateGeneralLCM(int arr[])so that it passes all test cases. TestCase 1: Input: [3,2,45,6,5,65280,4,3,46],9 Expected Output: 53820 TestCase 2: Input: [2,6,3,5,6,9,3,7,4,6,7],11 Expected Output: 360

9)

You are given a predefined class PrimeBank and also a collection of related functions that can be used to perform some basic operations on the structure. You must implement the function printPrime(int num, int digit)to accept the initial number num and number of digits n as inputs and prints all the prime numbers of n digits starting from the initial number num. Use the Primebank class and the associated functions for this task. (Please refer to the Helper Code tab for details regarding the class PrimeBank and the predefined functions around it) TestCase 1: Input: 891,3 Expected Output: [907, 911, 919, 937, 941, 953, 967, 971, 983, 991, 997] TestCase 2: Input: 123,2 Expected Output: Invalid Inputs

10) The function deleteDuplicate(int *arr, int len)takes an array arr of length len (len>= 0) as an input. It is supposed to remove duplicate integers from the input array arr such that for each distinct integer, the first occurrence is retained and all the duplicate elements following it are removed. For example, given the input array arr {2,3,2,2,5,6,6,7}, the expected output is {2,3,5,6,7}. The function compiles successfully but fails to return the desired result because of logical errors. Your task is to debug the program so that it passes all the test cases. TestCase 1: Input: [2,2,3,3,4,4],6 Expected Output:

[2,3,4] TestCase 2: Input: [21,21,21,21,21],5 Expected Output: [21] 11) The functiorfindMinElement(int *arrl, int len 1, int *arr2, int len2) accepts two integer arrays arr1, arr2 of length len1,len2, respectively. It is supposed to return the smallest element in both the input arrays. Another function sortArray(int *arr, int len)sorts the input array arrof length len in ascending order and returns it. Your task is to use the sortArray(int *arr, int len)function to complete the code in findMinElement(int *arr1, int len 1, int *arr2, int len2) so that it passes all the test cases TestCase 1: Input: [2,5,1,3,9,8,4,6,5,2,3,11]12,[11,13,2,4,15,17,67,44,2,100,23],11 Expected Output: 1 TestCase 2: Input: [-100,22,43,-912,56,89,85],7,[234,123,-456,234,890,-101],6 Expected Output: -912 12) The function printPattern(int num) prints even or odd numbers based on the value of the input argument num (num> 0). If the input number num is even, the function is expected to print the first num even whole numbers and in case it is odd, is expected to print the first num odd numbers. For example: given input 2, the function prints the string "0 2" (without quotes). The function compiles successfully but fails to print the desired result due to logical errors. Your task is to debug the program to pass all the test cases. TestCase 1: Input:

23 Expected Output: 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 TestCase 2: Input: 14 Expected Output: 0 2 4 6 8 10 12 14 16 18 20 22 24 26

13) The function getDay(int num) accepts a number num as input and is supposed to return the day to which it corresponds. The days are mapped to the number num in the following way. Monday is assigned 1, Tuesday 2, ... and Sunday is 7. The function compiles fine but fails to the return desired result for some test cases. Your task is to fix the program so that it passes all the test cases. TestCase 1: Input: 4 Expected Output: Thursday TestCase 2: Input: 1 Expected Output: Monday 14) The function getDigitSum(int*arr, int len) accepts an integer array arr of length len. It is supposed to calculate the sum of digits of the smallest element in the input array. It returns 1 if the calculated sum is even. Otherwise it returns 0. However, there is a compilation error in the code. Your task is to fix it so that the program works for all input values. Note: The function getDigitSum uses another function getSum(int num)that returns the sum of digits of the input number num.

15) A binary search tree (BST) is defined as a binary tree in which each node satisfies the property such that its value is larger than the value of every node in its left subtree, and less than or equal to the value of every node in its right subtree. The distance between two values in a binary search tree is the minimum number of edges traversed to reach from one value to the other. The function/method isSubBST accepts two input arguments – bRoot1 and bRoot2, representing the root of the first tree and the root of the second tree. It returns 1 if the tree with root bRoot2 is a subtree of a tree with root bRoot1, else it returns 0. The function/method compiles successfully but fails to return the desired result for some test cases. Your task is to fix the code so that it passes all the test cases. Note: The function/method isSubBSTuses another function/method areIdentical, which accepts two root nodes, bst1 and bst2, to check if these two binary search trees are identical or not. Helper Description The following structure is used to represent a node of the tree and is already implemented in the default code (Do not write this definition again in your code): struct TNode; typedef struct TNodetnode; struct TNode { tnode* left; tnode* right; int value; }; 16) The function printColor(int num) is supposed to print names of colors according to the given input number num. For example, if the values of num equal 1, 2, 3, 4, the function prints "Red': "Black'; "White': "Green" respectively. For any other values of num, it should print "No color”: The function compiles fine but fails to return the desired result for some test cases. Your task is to fix the code so that it passes all the test cases.

TestCase 1: Input: 3 Expected Output: White TestCase 2: Input: 5 Expected Output: No color 17) You are given a predefined structure PalindromeCollection and also a collection of functions that can be used to perform some basic operations on the structure. You must implement the function printPalindrome(int num, int n)to accepts initial number num and number of digits n as inputs and print all the palindrome numbers of n digits starting from the initial number num Use the PalindromeCollection structure and the associated functions for this task. (Please refer to the Helper Code tab for details regarding the structure PalindromeCollection and the predefined functions around it) 18) A ternary search tree is defined as a ternary tree in which a search, proceed character by character. compares the current character in the search string with the character at the current node. If the search character is lexicographically smaller, the search goes to the left child but if the search character is lexicographically larger, the search goes to the right child. When the search character is equal, the search goes to the middle child and proceeds to the next character in the search string. For example, ternary search tree for strings: CUP, CAT, CD,CUT C U

AP TDT

The function/method searchTernaryTree accepts three arguments tree, representing a ternary tree; inputStr, a string representing the word to be searched in the ternary tree and ptr an integer representing the index of the current character in inputStr The function/method is supposed to return 1 if the word is present in the tree else return 0. The function/method compiles successfully but fails to return the desired result for some/all test cases. Your task is to fix the code so that it passes all the test cases. Note: The initial value of ptr is 0. Helper Description The following structure represents Ternary Search Tree node and is already implemented in the default code (Do not write this definition again in your code): struct TernaryTreeNode { char data; unsigned isEnd0fString: 1; struct TernaryTreeNode *left, *mid, *right; }; typedef struct TernaryTreeNodeTTNode; TTNode* newNode(char data) { TTNode* temp = (TTNode*) malloc(sizeof(TTNode)) temp->data = data; temp->isEndOfString = 0; temp->left = temp->mid = temp->right = NULL; return temp; }

32. The current selected programming language is Java. We emphasize the submission of a fully working code over partially correct but efficient code. Once submitted, You cannot review this problem again. The version of JDK being used is 1.8. There is a colony of 8 cells arranged in a straight line where each day every cell competes with its adjacent cells(neighbours). Each day, for each cell, if its neighbours are both active or inactive. The cell becomes inactive the next day, otherwise it becomes active the next day.

Assumptions The two cells on the ends have single adjacent cell, so the other adjacent cell can be assumed to be always inactive. Even after updating the cell state, consider its previous state for updating the state of other cells. Update the cell information of all cells simultaneously. Write a method cellComplete of class Colony which takes an 8 element array of integers cells representing the current state of 8 cells and an integer days representing the number of days to simulate. The function should return an array representing the state of the cells after the given number of days. An integers value of represents an active cell and value of 0 represents an inactive cell. Test Case 1: Input: [1, 0, 0, 0, 0, 1, 0, 0], 1 Expected Return Value: [0, 1, 0, 0, 1, 0, 1, 0] Test Case 2: Input: [1, 1, 1, 0, 1, 1, 1, 1], 2 Expected Return Value: [0, 0, 0, 0, 0, 1, 1, 0]

Related Documents


More Documents from "tecnicogato27"

Code For Amcat-1
January 2021 1
Approved Supplier List
February 2021 0
45996525-scraping
March 2021 0