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

cpp input & output system basics
cpp input & output system basicscpp input & output system basics
cpp input & output system basicsgourav kottawar
 
19. Data Structures and Algorithm Complexity
19. Data Structures and Algorithm Complexity19. Data Structures and Algorithm Complexity
19. Data Structures and Algorithm ComplexityIntro C# Book
 
Infix prefix postfix expression -conversion
Infix  prefix postfix expression -conversionInfix  prefix postfix expression -conversion
Infix prefix postfix expression -conversionSyed Mustafa
 
AI_Session 15 Alpha–Beta Pruning.pptx
AI_Session 15 Alpha–Beta Pruning.pptxAI_Session 15 Alpha–Beta Pruning.pptx
AI_Session 15 Alpha–Beta Pruning.pptxAsst.prof M.Gokilavani
 
16. Java stacks and queues
16. Java stacks and queues16. Java stacks and queues
16. Java stacks and queuesIntro C# Book
 
Nested structure (Computer programming and utilization)
Nested structure (Computer programming and utilization)Nested structure (Computer programming and utilization)
Nested structure (Computer programming and utilization)Digvijaysinh Gohil
 
Python programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operationsPython programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operationsMegha V
 
array of object pointer in c++
array of object pointer in c++array of object pointer in c++
array of object pointer in c++Arpita Patel
 
Theory of automata and formal language
Theory of automata and formal languageTheory of automata and formal language
Theory of automata and formal languageRabia Khalid
 
USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2vikram mahendra
 
Unit 9. Structure and Unions
Unit 9. Structure and UnionsUnit 9. Structure and Unions
Unit 9. Structure and UnionsAshim Lamichhane
 
C Programming Storage classes, Recursion
C Programming Storage classes, RecursionC Programming Storage classes, Recursion
C Programming Storage classes, RecursionSreedhar Chowdam
 
Modeling with Recurrence Relations
Modeling with Recurrence RelationsModeling with Recurrence Relations
Modeling with Recurrence RelationsDevanshu Taneja
 

What's hot (20)

9 python data structure-2
9 python data structure-29 python data structure-2
9 python data structure-2
 
AD3251-Data Structures Design-Notes-Searching-Hashing.pdf
AD3251-Data Structures  Design-Notes-Searching-Hashing.pdfAD3251-Data Structures  Design-Notes-Searching-Hashing.pdf
AD3251-Data Structures Design-Notes-Searching-Hashing.pdf
 
Data types in C
Data types in CData types in C
Data types in C
 
Python programming : Strings
Python programming : StringsPython programming : Strings
Python programming : Strings
 
cpp input & output system basics
cpp input & output system basicscpp input & output system basics
cpp input & output system basics
 
19. Data Structures and Algorithm Complexity
19. Data Structures and Algorithm Complexity19. Data Structures and Algorithm Complexity
19. Data Structures and Algorithm Complexity
 
Infix prefix postfix expression -conversion
Infix  prefix postfix expression -conversionInfix  prefix postfix expression -conversion
Infix prefix postfix expression -conversion
 
AI_Session 15 Alpha–Beta Pruning.pptx
AI_Session 15 Alpha–Beta Pruning.pptxAI_Session 15 Alpha–Beta Pruning.pptx
AI_Session 15 Alpha–Beta Pruning.pptx
 
Type system
Type systemType system
Type system
 
16. Java stacks and queues
16. Java stacks and queues16. Java stacks and queues
16. Java stacks and queues
 
Nested structure (Computer programming and utilization)
Nested structure (Computer programming and utilization)Nested structure (Computer programming and utilization)
Nested structure (Computer programming and utilization)
 
Python programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operationsPython programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operations
 
array of object pointer in c++
array of object pointer in c++array of object pointer in c++
array of object pointer in c++
 
Theory of automata and formal language
Theory of automata and formal languageTheory of automata and formal language
Theory of automata and formal language
 
Pointers
PointersPointers
Pointers
 
Java input
Java inputJava input
Java input
 
USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2
 
Unit 9. Structure and Unions
Unit 9. Structure and UnionsUnit 9. Structure and Unions
Unit 9. Structure and Unions
 
C Programming Storage classes, Recursion
C Programming Storage classes, RecursionC Programming Storage classes, Recursion
C Programming Storage classes, Recursion
 
Modeling with Recurrence Relations
Modeling with Recurrence RelationsModeling with Recurrence Relations
Modeling with Recurrence Relations
 

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

JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
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
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
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
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 

Recently uploaded (20)

JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
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
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
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
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 

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