SlideShare a Scribd company logo
1 of 7
MUM TEST

1. Write a function that accepts an array of non-negative integers and returns the second largest
integer in the array. Return -1 if there is no second largest. You may assume that the input array has
no negative values in it.



If you are programming in Java or C#, the signature of the function is

int f(int[ ] a)



If you are programming in C or C#, the signature of the function is

int f(int a[ ], int len) where len is the number of elements in a.

Examples:

if the input array is    return

{1, 2, 3, 4}               3

{{4, 1, 2, 3}}             3

{1, 1, 2, 2}              1

{1, 1}                   -1

{1}                      -1

{}                       -1



2. Write a function that takes an array of integers as an argument and returns a value based on the
sums of the even and odd numbers in the array. Let X = the sum of the odd numbers in the array and
let Y = the sum of the even numbers. The function should return X - Y



If you are using Java or C#, the signature of the function is:

int f(int[ ] a)

If you are using C or C++, the signature of the function is:

int f(int[ ] a, int len) where len is the number of elements in a.


1|Page
Examples

if input array is return

{1}                     1

{1, 2}                  -1

{1, 2, 3}               2

{1, 2, 3, 4}            -2

{3, 3, 4, 4}            -2

{3, 2, 3, 4}            0

{4, 1, 2, 3}            -2

{1, 1}                  2

{}                      0



3. Write a function that accepts a character array, a zero-based start position and a length. It should
return a character array containing containing length characters starting with the start character of
the input array. The function should do error checking on the start position and the length and return
null if the either value is not legal.



If you are programming in Java or C#, the function signature is:

char[ ] f(char[ ] a, int start, int len)



If you are programming in C or C++, the function signature is:

char * f(char a[ ], int start, int len, int lenA) where lenA is the number of elements in a.

Examples

if input parameters are               return

{'a', 'b', 'c'}, 0, 4                null

{'a', 'b', 'c'}, 0, 3              {'a', 'b', 'c'}

{'a', 'b', 'c'}, 0, 2                {'a', 'b'}

2|Page
{'a', 'b', 'c'}, 0, 1             {'a'}

{'a', 'b', 'c'}, 1, 3                  null

{'a', 'b', 'c'}, 1, 2             {'b', 'c'}

{'a', 'b', 'c'}, 1, 1             {'b'}

{'a', 'b', 'c'}, 2, 2             null

{'a', 'b', 'c'}, 2, 1             {'c'}

{'a', 'b', 'c'}, 3, 1             null

{'a', 'b', 'c'}, 1, 0             {}

{'a', 'b', 'c'}, -1, 2            null

{'a', 'b', 'c'}, -1, -2           null

{}, 0, 1                          null




                                          Answers
First answer
 public static void main()

 {

     a1(new int[]{1, 2, 3, 4});

     a1(new int[]{4, 1, 2, 3});

     a1(new int[]{1, 1, 2, 2});

     a1(new int[]{1, 1});

     a1(new int[]{1});

     a1(new int[]{});

 }




3|Page
static int a1(int[] a)

{

    int max1 = -1;

    int max2 = -1;



    for (int i=0; i<a.length; i++)

    {

        if (a[i] > max1)

        {

            max2 = max1;

            max1 = a[i];

        }

        else if (a[i] != max1 && a[i] > max2)

            max2 = a[i];

    }



    return max2;

}




Second answer

public static void main()

{

    a2(new int[] {1});

4|Page
a2(new int[] {1, 2});

    a2(new int[] {1, 2, 3});

    a2(new int[] {1, 2, 3, 4});

    a2(new int[] {3, 3, 4, 4});

    a2(new int[] {3, 2, 3, 4});

    a2(new int[] {4, 1, 2, 3});

    a2(new int[] {1, 1});

    a2(new int[] {});

}



static int a2(int[] a)

{

    int sumEven = 0;

    int sumOdd = 0;



    for (int i=0; i<a.length; i++)

    {

        if (a[i]%2 == 0)

         sumEven += a[i];

        else

         sumOdd += a[i];

    }



    return sumOdd - sumEven;

}



5|Page
Third answer

public static void main()

{

    a3(new char[]{'a', 'b', 'c'}, 0, 4);

    a3(new char[]{'a', 'b', 'c'}, 0, 3);

    a3(new char[]{'a', 'b', 'c'}, 0, 2);

    a3(new char[]{'a', 'b', 'c'}, 0, 1);

    a3(new char[]{'a', 'b', 'c'}, 1, 3);

    a3(new char[]{'a', 'b', 'c'}, 1, 2);

    a3(new char[]{'a', 'b', 'c'}, 1, 1);

    a3(new char[]{'a', 'b', 'c'}, 2, 2);

    a3(new char[]{'a', 'b', 'c'}, 2, 1);

    a3(new char[]{'a', 'b', 'c'}, 3, 1);

    a3(new char[]{'a', 'b', 'c'}, 1, 0);

    a3(new char[]{}, 0, 1);

    a3(new char[]{'a', 'b', 'c'}, -1, 2);

    a3(new char[]{'a', 'b', 'c'}, -1, -2);

}



static char[] a3(char[] a, int start, int length)

{

    if (length < 0 || start < 0 || start+length-1>=a.length)

    {


6|Page
return null;

    }



    char[] sub = new char[length];

    for (int i=start, j=0; j<length; i++, j++)

    {

        sub[j] = a[i];

    }



    return sub;

}




7|Page

More Related Content

What's hot (20)

C++ string
C++ stringC++ string
C++ string
 
Strings in c
Strings in cStrings in c
Strings in c
 
string in C
string in Cstring in C
string in C
 
for loop in java
for loop in java for loop in java
for loop in java
 
Strings
StringsStrings
Strings
 
String in c
String in cString in c
String in c
 
Stl Containers
Stl ContainersStl Containers
Stl Containers
 
6. static keyword
6. static keyword6. static keyword
6. static keyword
 
standard template library(STL) in C++
standard template library(STL) in C++standard template library(STL) in C++
standard template library(STL) in C++
 
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdfMANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
 
Array
ArrayArray
Array
 
Pointer in C++
Pointer in C++Pointer in C++
Pointer in C++
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Sql functions
Sql functionsSql functions
Sql functions
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
Managing I/O in c++
Managing I/O in c++Managing I/O in c++
Managing I/O in c++
 
C language industrial training report
C language industrial training reportC language industrial training report
C language industrial training report
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
 
String in c programming
String in c programmingString in c programming
String in c programming
 

Viewers also liked

Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentalsOm Ganesh
 
Function in c program
Function in c programFunction in c program
Function in c programumesh patil
 
Bai tap loi_giai_xac_suat_thong_ke_2733
Bai tap loi_giai_xac_suat_thong_ke_2733Bai tap loi_giai_xac_suat_thong_ke_2733
Bai tap loi_giai_xac_suat_thong_ke_2733behieuso1
 
Bài tập Xác suất thống kê
Bài tập Xác suất thống kêBài tập Xác suất thống kê
Bài tập Xác suất thống kêHọc Huỳnh Bá
 

Viewers also liked (7)

Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
 
Function in c program
Function in c programFunction in c program
Function in c program
 
Data Structures (BE)
Data Structures (BE)Data Structures (BE)
Data Structures (BE)
 
Testing In Java
Testing In JavaTesting In Java
Testing In Java
 
Bai tap loi_giai_xac_suat_thong_ke_2733
Bai tap loi_giai_xac_suat_thong_ke_2733Bai tap loi_giai_xac_suat_thong_ke_2733
Bai tap loi_giai_xac_suat_thong_ke_2733
 
bai tap co loi giai xac suat thong ke
bai tap co loi giai xac suat thong kebai tap co loi giai xac suat thong ke
bai tap co loi giai xac suat thong ke
 
Bài tập Xác suất thống kê
Bài tập Xác suất thống kêBài tập Xác suất thống kê
Bài tập Xác suất thống kê
 

Similar to Maharishi University of Management (MSc Computer Science test questions)

131 Lab slides (all in one)
131 Lab slides (all in one)131 Lab slides (all in one)
131 Lab slides (all in one)Tak Lee
 
Virtusa questions placement preparation guide
Virtusa questions placement preparation guideVirtusa questions placement preparation guide
Virtusa questions placement preparation guideThalaAjith33
 
C (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptxC (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptxrohinitalekar1
 
C++ Programming Homework Help
C++ Programming Homework HelpC++ Programming Homework Help
C++ Programming Homework HelpC++ Homework Help
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2YOGESH SINGH
 
Leet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm ProblemsLeet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm ProblemsSunil Yadav
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functionsSwarup Boro
 
Array 31.8.2020 updated
Array 31.8.2020 updatedArray 31.8.2020 updated
Array 31.8.2020 updatedvrgokila
 
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdfrushabhshah600
 
Homework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdfHomework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdfaroraopticals15
 
Computation of Semi-Magic Squares Generated by Serpentine Matrices
Computation of Semi-Magic Squares Generated by Serpentine MatricesComputation of Semi-Magic Squares Generated by Serpentine Matrices
Computation of Semi-Magic Squares Generated by Serpentine MatricesLossian Barbosa Bacelar Miranda
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programmingPrudhviVuda
 

Similar to Maharishi University of Management (MSc Computer Science test questions) (20)

131 Lab slides (all in one)
131 Lab slides (all in one)131 Lab slides (all in one)
131 Lab slides (all in one)
 
Virtusa questions placement preparation guide
Virtusa questions placement preparation guideVirtusa questions placement preparation guide
Virtusa questions placement preparation guide
 
Qno 3 (a)
Qno 3 (a)Qno 3 (a)
Qno 3 (a)
 
C (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptxC (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptx
 
C++ Programming Homework Help
C++ Programming Homework HelpC++ Programming Homework Help
C++ Programming Homework Help
 
C Programming Unit-3
C Programming Unit-3C Programming Unit-3
C Programming Unit-3
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2
 
Leet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm ProblemsLeet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm Problems
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
 
Array 31.8.2020 updated
Array 31.8.2020 updatedArray 31.8.2020 updated
Array 31.8.2020 updated
 
Array&amp;string
Array&amp;stringArray&amp;string
Array&amp;string
 
Arrays
ArraysArrays
Arrays
 
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
 
Homework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdfHomework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdf
 
Array
ArrayArray
Array
 
Unit 3 arrays and_string
Unit 3 arrays and_stringUnit 3 arrays and_string
Unit 3 arrays and_string
 
Chap 6 c++
Chap 6 c++Chap 6 c++
Chap 6 c++
 
Array
ArrayArray
Array
 
Computation of Semi-Magic Squares Generated by Serpentine Matrices
Computation of Semi-Magic Squares Generated by Serpentine MatricesComputation of Semi-Magic Squares Generated by Serpentine Matrices
Computation of Semi-Magic Squares Generated by Serpentine Matrices
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 

Recently uploaded

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesShubhangi Sonawane
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 

Recently uploaded (20)

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 

Maharishi University of Management (MSc Computer Science test questions)

  • 1. MUM TEST 1. Write a function that accepts an array of non-negative integers and returns the second largest integer in the array. Return -1 if there is no second largest. You may assume that the input array has no negative values in it. If you are programming in Java or C#, the signature of the function is int f(int[ ] a) If you are programming in C or C#, the signature of the function is int f(int a[ ], int len) where len is the number of elements in a. Examples: if the input array is return {1, 2, 3, 4} 3 {{4, 1, 2, 3}} 3 {1, 1, 2, 2} 1 {1, 1} -1 {1} -1 {} -1 2. Write a function that takes an array of integers as an argument and returns a value based on the sums of the even and odd numbers in the array. Let X = the sum of the odd numbers in the array and let Y = the sum of the even numbers. The function should return X - Y If you are using Java or C#, the signature of the function is: int f(int[ ] a) If you are using C or C++, the signature of the function is: int f(int[ ] a, int len) where len is the number of elements in a. 1|Page
  • 2. Examples if input array is return {1} 1 {1, 2} -1 {1, 2, 3} 2 {1, 2, 3, 4} -2 {3, 3, 4, 4} -2 {3, 2, 3, 4} 0 {4, 1, 2, 3} -2 {1, 1} 2 {} 0 3. Write a function that accepts a character array, a zero-based start position and a length. It should return a character array containing containing length characters starting with the start character of the input array. The function should do error checking on the start position and the length and return null if the either value is not legal. If you are programming in Java or C#, the function signature is: char[ ] f(char[ ] a, int start, int len) If you are programming in C or C++, the function signature is: char * f(char a[ ], int start, int len, int lenA) where lenA is the number of elements in a. Examples if input parameters are return {'a', 'b', 'c'}, 0, 4 null {'a', 'b', 'c'}, 0, 3 {'a', 'b', 'c'} {'a', 'b', 'c'}, 0, 2 {'a', 'b'} 2|Page
  • 3. {'a', 'b', 'c'}, 0, 1 {'a'} {'a', 'b', 'c'}, 1, 3 null {'a', 'b', 'c'}, 1, 2 {'b', 'c'} {'a', 'b', 'c'}, 1, 1 {'b'} {'a', 'b', 'c'}, 2, 2 null {'a', 'b', 'c'}, 2, 1 {'c'} {'a', 'b', 'c'}, 3, 1 null {'a', 'b', 'c'}, 1, 0 {} {'a', 'b', 'c'}, -1, 2 null {'a', 'b', 'c'}, -1, -2 null {}, 0, 1 null Answers First answer public static void main() { a1(new int[]{1, 2, 3, 4}); a1(new int[]{4, 1, 2, 3}); a1(new int[]{1, 1, 2, 2}); a1(new int[]{1, 1}); a1(new int[]{1}); a1(new int[]{}); } 3|Page
  • 4. static int a1(int[] a) { int max1 = -1; int max2 = -1; for (int i=0; i<a.length; i++) { if (a[i] > max1) { max2 = max1; max1 = a[i]; } else if (a[i] != max1 && a[i] > max2) max2 = a[i]; } return max2; } Second answer public static void main() { a2(new int[] {1}); 4|Page
  • 5. a2(new int[] {1, 2}); a2(new int[] {1, 2, 3}); a2(new int[] {1, 2, 3, 4}); a2(new int[] {3, 3, 4, 4}); a2(new int[] {3, 2, 3, 4}); a2(new int[] {4, 1, 2, 3}); a2(new int[] {1, 1}); a2(new int[] {}); } static int a2(int[] a) { int sumEven = 0; int sumOdd = 0; for (int i=0; i<a.length; i++) { if (a[i]%2 == 0) sumEven += a[i]; else sumOdd += a[i]; } return sumOdd - sumEven; } 5|Page
  • 6. Third answer public static void main() { a3(new char[]{'a', 'b', 'c'}, 0, 4); a3(new char[]{'a', 'b', 'c'}, 0, 3); a3(new char[]{'a', 'b', 'c'}, 0, 2); a3(new char[]{'a', 'b', 'c'}, 0, 1); a3(new char[]{'a', 'b', 'c'}, 1, 3); a3(new char[]{'a', 'b', 'c'}, 1, 2); a3(new char[]{'a', 'b', 'c'}, 1, 1); a3(new char[]{'a', 'b', 'c'}, 2, 2); a3(new char[]{'a', 'b', 'c'}, 2, 1); a3(new char[]{'a', 'b', 'c'}, 3, 1); a3(new char[]{'a', 'b', 'c'}, 1, 0); a3(new char[]{}, 0, 1); a3(new char[]{'a', 'b', 'c'}, -1, 2); a3(new char[]{'a', 'b', 'c'}, -1, -2); } static char[] a3(char[] a, int start, int length) { if (length < 0 || start < 0 || start+length-1>=a.length) { 6|Page
  • 7. return null; } char[] sub = new char[length]; for (int i=start, j=0; j<length; i++, j++) { sub[j] = a[i]; } return sub; } 7|Page