SlideShare a Scribd company logo
1 of 9
Download to read offline
GLA-01: Java, Big O and Lists
Overview and Submission Requirements
Your task is to work individually to create a series of methods that can solve tech interview
questions, as well as analyze the computational complexity of these solutions. You should
complete your entire lab in a single file named InterviewQuestions.java. Once you have
completed the lab, you should submit InterviewQuestions.java to D2L.
External Resources and Code
As per the Academic Integrity guidelines, you may not copy code (even with modification) from
anywhere, including the internet, other students, or your textbook. You may not consult other
students or look at their code. You may not share your code with other students. Any submission
that violates the academic honesty guidelines will receive an automatic 0 and will be considered
an academic honesty violation.
Background: Tech Interviews
Technical interviews are a common part of the hiring process in the software development field.
Although they can range in format, one of the most common techniques is to ask candidates to
solve a couple of programming problems on a whiteboard and then explain their solutions. This
GLA takes the form of a number of small programming problems that could appear in such an
interview.
For each problem, implement the method in InterviewQuestions.java, explain what n is, and state
the Big(O) complexity of your solution.
Problem One: Pricey Neighbours
Suppose you have an array of doubles that represents the value of each house on a long block of
houses. Find the three adjacent houses that have the largest combined value, and return the
smallest index of the array (leftmost house).
Your solution should be of the form: (Note: you may use the provided template)
public int findPriceyNeighbours(double[] prices)
The method header should state what n is (Java Commented form), and what the Big(O)
complexity of your solution is.
Problem Two: Common Friends
Suppose you have two ArrayLists, each of which represents the friends of a single person. Write
a method to find the common friends between those two people-- that is, a list of Strings that
appear in both input lists.
Your solution should be of the form: (Note: you may use the provided template)
public ArrayList<String> commonFriends(ArrayList<String> friendListOne, ArrayList<String>
friendListTwo)
The method header should state what n is (Java Commented form), and what the Big(O)
complexity of your solution is.
Problem Three: Count Divisors (Note: you may use the provided template)
Suppose you have an array of integers. Count each pair of indices in that array in which the value
at the first index is evenly divisible by the values at the following indices.
Your solution should be of the form:
public int countDivisors(int[] values)
The method header should state what n is (Java Commented form), and what the Big(O)
complexity of your solution is.
Problem Four: First Odd Number
Suppose you have an array of integers. All of the integers from indexes 0 up to (But not
including) a target index are even. All integers from that target index onwards are odd. Given
such an array, find the index of the first odd number.
Your solution should be of the form: (Note: you may use the provided template)
public int findIndexOfFirstOddNumber(int[] numbers)
The method header should state what n is (Java Commented form), and what the Big(O)
complexity of your solution is.
I have a starter code: do not change anything on the second file of code:
FIRST file would be named InterviewQuestions.java:
import java.util.ArrayList;
public class InterviewQuestions {
public int findPriceyNeighbours(double[] prices)
{
//ToDo
return -1;
}
public ArrayList<String> commonFriends(ArrayList<String> friendListOne, ArrayList<String>
friendListTwo)
{
ArrayList<String> common=new ArrayList<String>();
//ToDo
return common;
}
public int countDivisors(int[] values)
{
//ToDo
return -1;
}
public int findIndexOfFirstOddNumber(int[] numbers)
{
//ToDo
return -1;
}
}
SECOND FILE named InterviewQuestionsTest.java(DO NOT CHANGE ANYTHING)
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
public class InterviewQuestionsTest {
private static Random r;
static
{
r=new Random(2);
}
public static int [] GetRandomArray(int n, int min, int max)
{
int []a=new int[n];
for(int i=0; i<a.length; i++)
{
a[i]=r.nextInt(max-min+1)+min;
}
return a;
}
public static void displayDoubleArray(double []a)
{
for(int i=0; i<a.length; i++)
{
System.out.printf("%.2fn",a[i]);
}
}
public static void displayIntArray(int []a)
{
for(int i=0; i<a.length; i++)
{
System.out.print(a[i]+" ");
}
}
public static ArrayList<String> getNRandomNames(int n, ArrayList<String>nameList)
{
ArrayList<String> friendList=new ArrayList<String>();
for(int i=0; i<n; i++)
{
friendList.add(nameList.get(r.nextInt(nameList.size())));
}
return friendList;
}
public static void displayNames(String name, ArrayList<String>nameList)
{
System.out.print(name+"'s Friend List: ");
for(var n : nameList)
{
System.out.print(n+", ");
}
System.out.println();
}
public static void makeEvenAllThenOddAll(int []numbers, int pos)
{
for(int i=0; i<pos; i++)
{
if(numbers[i]%2==1)
{
numbers[i]++;
}
}
for(int i=pos; i<numbers.length; i++)
{
if(numbers[i]%2==0)
{
numbers[i]++;
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
InterviewQuestions solution=new InterviewQuestions();
int n=10;
double []HousePrice= Arrays.stream(GetRandomArray(n, 500000,
1000000)).asDoubleStream().toArray();
System.out.println("Problem One: Pricey Neighbours");
System.out.println("House Prices: ");
displayDoubleArray(HousePrice);
System.out.println("First index of Pricey Neighbours is: "+
solution.findPriceyNeighbours(HousePrice));
System.out.println("nProblem Two: Common Friends");
ArrayList<String>nameList= new ArrayList<>(List.of(
"Liam", "Noah", "Oliver",
"William","Elijah","James","Benjamin","Lucas","Mason","Ethan","Alexander","Henry","Jacob"
,"Michael", "Daniel",
"Logan","Jackson","Sebastian","Jack","Aiden","Owen","Samuel","Matthew","Joseph","Levi","
Mateo","David","John","Wyatt"));
ArrayList<String> davidsFriends=getNRandomNames(10,nameList);
displayNames("David", davidsFriends);
ArrayList<String> susansFriends=getNRandomNames(10,nameList);
displayNames("Susan", susansFriends);
ArrayList<String> commonFriends=solution.commonFriends(davidsFriends, susansFriends);
displayNames("Common Friends", commonFriends);
System.out.println("nProblem Three: Count Divisors");
n=6;
int []values=GetRandomArray(n, 5, 20);
displayIntArray(values);
System.out.println("nCount: "+solution.countDivisors(values));
n=10;
System.out.println("nProblem Four: First Odd Number");
int []numbers=GetRandomArray(n, 10, 50);
makeEvenAllThenOddAll(numbers, r.nextInt(n));
displayIntArray(numbers);
System.out.println("nFirst odd number's index is:
"+solution.findIndexOfFirstOddNumber(numbers));
}
}
/*If you have implemented your GLA correctly, the following will be your program's output:
Problem One: Pricey Neighbours
House Prices:
622968.00
520112.00
840169.00
925050.00
916256.00
909680.00
650372.00
979577.00
656166.00
891104.00
First index of Pricey Neighbours is: 3
Problem Two: Common Friends
David's Friend List: Jacob, Benjamin, Joseph, Owen, Michael, Lucas, Wyatt, Owen, Jacob,
Alexander,
Susan's Friend List: Jack, Alexander, Samuel, Henry, Daniel, Logan, Joseph, Benjamin,
Sebastian, Wyatt,
Common Friends's Friend List: Benjamin, Joseph, Wyatt, Alexander,
Problem Three: Count Divisors
10 13 20 15 13 10
Count: 3
Problem Four: First Odd Number
16 20 40 12 35 19 23 31 35 11
First odd number's index is: 4
*/

More Related Content

Similar to GLA-01- Java- Big O and Lists Overview and Submission Requirements You.pdf

classes object fgfhdfgfdgfgfgfgfdoop.pptx
classes object  fgfhdfgfdgfgfgfgfdoop.pptxclasses object  fgfhdfgfdgfgfgfgfdoop.pptx
classes object fgfhdfgfdgfgfgfgfdoop.pptxarjun431527
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slotsmha4
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slotsmha4
 
Object Oriented Programming with C#
Object Oriented Programming with C#Object Oriented Programming with C#
Object Oriented Programming with C#SyedUmairAli9
 
C# / Java Language Comparison
C# / Java Language ComparisonC# / Java Language Comparison
C# / Java Language ComparisonRobert Bachmann
 
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...Raffi Khatchadourian
 
Basics of java 2
Basics of java 2Basics of java 2
Basics of java 2Raghu nath
 
Getting Started - Console Program and Problem Solving
Getting Started - Console Program and Problem SolvingGetting Started - Console Program and Problem Solving
Getting Started - Console Program and Problem SolvingHock Leng PUAH
 
SPF Getting Started - Console Program
SPF Getting Started - Console ProgramSPF Getting Started - Console Program
SPF Getting Started - Console ProgramHock Leng PUAH
 
Chapter 2.4
Chapter 2.4Chapter 2.4
Chapter 2.4sotlsoc
 
DevNation'15 - Using Lambda Expressions to Query a Datastore
DevNation'15 - Using Lambda Expressions to Query a DatastoreDevNation'15 - Using Lambda Expressions to Query a Datastore
DevNation'15 - Using Lambda Expressions to Query a DatastoreXavier Coulon
 
Modern_2.pptx for java
Modern_2.pptx for java Modern_2.pptx for java
Modern_2.pptx for java MayaTofik
 
IRE- Algorithm Name Detection in Research Papers
IRE- Algorithm Name Detection in Research PapersIRE- Algorithm Name Detection in Research Papers
IRE- Algorithm Name Detection in Research PapersSriTeja Allaparthi
 
C Sharp: Basic to Intermediate Part 01
C Sharp: Basic to Intermediate Part 01C Sharp: Basic to Intermediate Part 01
C Sharp: Basic to Intermediate Part 01Zafor Iqbal
 

Similar to GLA-01- Java- Big O and Lists Overview and Submission Requirements You.pdf (20)

classes object fgfhdfgfdgfgfgfgfdoop.pptx
classes object  fgfhdfgfdgfgfgfgfdoop.pptxclasses object  fgfhdfgfdgfgfgfgfdoop.pptx
classes object fgfhdfgfdgfgfgfgfdoop.pptx
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots
 
Object Oriented Programming with C#
Object Oriented Programming with C#Object Oriented Programming with C#
Object Oriented Programming with C#
 
C# / Java Language Comparison
C# / Java Language ComparisonC# / Java Language Comparison
C# / Java Language Comparison
 
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
Basics of java 2
Basics of java 2Basics of java 2
Basics of java 2
 
Java programming-examples
Java programming-examplesJava programming-examples
Java programming-examples
 
Getting Started - Console Program and Problem Solving
Getting Started - Console Program and Problem SolvingGetting Started - Console Program and Problem Solving
Getting Started - Console Program and Problem Solving
 
SPF Getting Started - Console Program
SPF Getting Started - Console ProgramSPF Getting Started - Console Program
SPF Getting Started - Console Program
 
Chapter 2.4
Chapter 2.4Chapter 2.4
Chapter 2.4
 
Getting started with R
Getting started with RGetting started with R
Getting started with R
 
DevNation'15 - Using Lambda Expressions to Query a Datastore
DevNation'15 - Using Lambda Expressions to Query a DatastoreDevNation'15 - Using Lambda Expressions to Query a Datastore
DevNation'15 - Using Lambda Expressions to Query a Datastore
 
Modern_2.pptx for java
Modern_2.pptx for java Modern_2.pptx for java
Modern_2.pptx for java
 
IRE- Algorithm Name Detection in Research Papers
IRE- Algorithm Name Detection in Research PapersIRE- Algorithm Name Detection in Research Papers
IRE- Algorithm Name Detection in Research Papers
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
 
C Sharp: Basic to Intermediate Part 01
C Sharp: Basic to Intermediate Part 01C Sharp: Basic to Intermediate Part 01
C Sharp: Basic to Intermediate Part 01
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
 
3 jf h-linearequations
3  jf h-linearequations3  jf h-linearequations
3 jf h-linearequations
 

More from NicholasflqStewartl

he amount of income taxesThe amount of income taxes A- the corporation.pdf
he amount of income taxesThe amount of income taxes A- the corporation.pdfhe amount of income taxesThe amount of income taxes A- the corporation.pdf
he amount of income taxesThe amount of income taxes A- the corporation.pdfNicholasflqStewartl
 
Having a hard time with this one- Fill in the blanks with the follow.pdf
Having a hard time with this one-   Fill in the blanks with the follow.pdfHaving a hard time with this one-   Fill in the blanks with the follow.pdf
Having a hard time with this one- Fill in the blanks with the follow.pdfNicholasflqStewartl
 
Having a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdfHaving a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdfNicholasflqStewartl
 
Harriet- Herm- and Ronde formed an S corporation called Innovet- Harri.pdf
Harriet- Herm- and Ronde formed an S corporation called Innovet- Harri.pdfHarriet- Herm- and Ronde formed an S corporation called Innovet- Harri.pdf
Harriet- Herm- and Ronde formed an S corporation called Innovet- Harri.pdfNicholasflqStewartl
 
Hardworking Americans Should Not Be Living in Poverty has fallen to $6.pdf
Hardworking Americans Should Not Be Living in Poverty has fallen to $6.pdfHardworking Americans Should Not Be Living in Poverty has fallen to $6.pdf
Hardworking Americans Should Not Be Living in Poverty has fallen to $6.pdfNicholasflqStewartl
 
Government and Not for profit accounting 2022 CAFR (City of Anaheim) S.pdf
Government and Not for profit accounting 2022 CAFR (City of Anaheim) S.pdfGovernment and Not for profit accounting 2022 CAFR (City of Anaheim) S.pdf
Government and Not for profit accounting 2022 CAFR (City of Anaheim) S.pdfNicholasflqStewartl
 
Hammond Manufacturing Inc- was legally incorporated on January 2- 2020.pdf
Hammond Manufacturing Inc- was legally incorporated on January 2- 2020.pdfHammond Manufacturing Inc- was legally incorporated on January 2- 2020.pdf
Hammond Manufacturing Inc- was legally incorporated on January 2- 2020.pdfNicholasflqStewartl
 
Hacer un programa en c++ que lea la frase y determine que caracteres s.pdf
Hacer un programa en c++ que lea la frase y determine que caracteres s.pdfHacer un programa en c++ que lea la frase y determine que caracteres s.pdf
Hacer un programa en c++ que lea la frase y determine que caracteres s.pdfNicholasflqStewartl
 
Given the regular expression- 0(01)0 (a) Construct and -NFA and draw i.pdf
Given the regular expression- 0(01)0 (a) Construct and -NFA and draw i.pdfGiven the regular expression- 0(01)0 (a) Construct and -NFA and draw i.pdf
Given the regular expression- 0(01)0 (a) Construct and -NFA and draw i.pdfNicholasflqStewartl
 
Grouper Corporation is authorized to issue both preferred and commonst.pdf
Grouper Corporation is authorized to issue both preferred and commonst.pdfGrouper Corporation is authorized to issue both preferred and commonst.pdf
Grouper Corporation is authorized to issue both preferred and commonst.pdfNicholasflqStewartl
 
Guessing or knowing the initial TCP sequence number (ISN) that a serve.pdf
Guessing or knowing the initial TCP sequence number (ISN) that a serve.pdfGuessing or knowing the initial TCP sequence number (ISN) that a serve.pdf
Guessing or knowing the initial TCP sequence number (ISN) that a serve.pdfNicholasflqStewartl
 
Given the following XML fragment- what XPath expression would select a.pdf
Given the following XML fragment- what XPath expression would select a.pdfGiven the following XML fragment- what XPath expression would select a.pdf
Given the following XML fragment- what XPath expression would select a.pdfNicholasflqStewartl
 
Greener Pastures Corporation borrowed $1-100-000 on November 1- 2021-.pdf
Greener Pastures Corporation borrowed $1-100-000 on November 1- 2021-.pdfGreener Pastures Corporation borrowed $1-100-000 on November 1- 2021-.pdf
Greener Pastures Corporation borrowed $1-100-000 on November 1- 2021-.pdfNicholasflqStewartl
 
Given the following for the Titan Company- the company began operation.pdf
Given the following for the Titan Company- the company began operation.pdfGiven the following for the Titan Company- the company began operation.pdf
Given the following for the Titan Company- the company began operation.pdfNicholasflqStewartl
 
Given the following errors and class in Java- How are these errors fix.pdf
Given the following errors and class in Java- How are these errors fix.pdfGiven the following errors and class in Java- How are these errors fix.pdf
Given the following errors and class in Java- How are these errors fix.pdfNicholasflqStewartl
 
Given the following class in Java- public class ThreeTenDynArray-T- {.pdf
Given the following class in Java-  public class ThreeTenDynArray-T- {.pdfGiven the following class in Java-  public class ThreeTenDynArray-T- {.pdf
Given the following class in Java- public class ThreeTenDynArray-T- {.pdfNicholasflqStewartl
 
Given Information #1- Period 1 is when Devah is working and earning mo.pdf
Given Information #1- Period 1 is when Devah is working and earning mo.pdfGiven Information #1- Period 1 is when Devah is working and earning mo.pdf
Given Information #1- Period 1 is when Devah is working and earning mo.pdfNicholasflqStewartl
 
Give concise and substantial answers by relating your answers to your.pdf
Give concise and substantial answers by relating your answers to your.pdfGive concise and substantial answers by relating your answers to your.pdf
Give concise and substantial answers by relating your answers to your.pdfNicholasflqStewartl
 
Given a stream of strings- remove all empty strings- import java-uti.pdf
Given a stream of strings- remove all empty strings-   import java-uti.pdfGiven a stream of strings- remove all empty strings-   import java-uti.pdf
Given a stream of strings- remove all empty strings- import java-uti.pdfNicholasflqStewartl
 
Given an IntNode struct and the operating functions for a linked list-.pdf
Given an IntNode struct and the operating functions for a linked list-.pdfGiven an IntNode struct and the operating functions for a linked list-.pdf
Given an IntNode struct and the operating functions for a linked list-.pdfNicholasflqStewartl
 

More from NicholasflqStewartl (20)

he amount of income taxesThe amount of income taxes A- the corporation.pdf
he amount of income taxesThe amount of income taxes A- the corporation.pdfhe amount of income taxesThe amount of income taxes A- the corporation.pdf
he amount of income taxesThe amount of income taxes A- the corporation.pdf
 
Having a hard time with this one- Fill in the blanks with the follow.pdf
Having a hard time with this one-   Fill in the blanks with the follow.pdfHaving a hard time with this one-   Fill in the blanks with the follow.pdf
Having a hard time with this one- Fill in the blanks with the follow.pdf
 
Having a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdfHaving a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdf
 
Harriet- Herm- and Ronde formed an S corporation called Innovet- Harri.pdf
Harriet- Herm- and Ronde formed an S corporation called Innovet- Harri.pdfHarriet- Herm- and Ronde formed an S corporation called Innovet- Harri.pdf
Harriet- Herm- and Ronde formed an S corporation called Innovet- Harri.pdf
 
Hardworking Americans Should Not Be Living in Poverty has fallen to $6.pdf
Hardworking Americans Should Not Be Living in Poverty has fallen to $6.pdfHardworking Americans Should Not Be Living in Poverty has fallen to $6.pdf
Hardworking Americans Should Not Be Living in Poverty has fallen to $6.pdf
 
Government and Not for profit accounting 2022 CAFR (City of Anaheim) S.pdf
Government and Not for profit accounting 2022 CAFR (City of Anaheim) S.pdfGovernment and Not for profit accounting 2022 CAFR (City of Anaheim) S.pdf
Government and Not for profit accounting 2022 CAFR (City of Anaheim) S.pdf
 
Hammond Manufacturing Inc- was legally incorporated on January 2- 2020.pdf
Hammond Manufacturing Inc- was legally incorporated on January 2- 2020.pdfHammond Manufacturing Inc- was legally incorporated on January 2- 2020.pdf
Hammond Manufacturing Inc- was legally incorporated on January 2- 2020.pdf
 
Hacer un programa en c++ que lea la frase y determine que caracteres s.pdf
Hacer un programa en c++ que lea la frase y determine que caracteres s.pdfHacer un programa en c++ que lea la frase y determine que caracteres s.pdf
Hacer un programa en c++ que lea la frase y determine que caracteres s.pdf
 
Given the regular expression- 0(01)0 (a) Construct and -NFA and draw i.pdf
Given the regular expression- 0(01)0 (a) Construct and -NFA and draw i.pdfGiven the regular expression- 0(01)0 (a) Construct and -NFA and draw i.pdf
Given the regular expression- 0(01)0 (a) Construct and -NFA and draw i.pdf
 
Grouper Corporation is authorized to issue both preferred and commonst.pdf
Grouper Corporation is authorized to issue both preferred and commonst.pdfGrouper Corporation is authorized to issue both preferred and commonst.pdf
Grouper Corporation is authorized to issue both preferred and commonst.pdf
 
Guessing or knowing the initial TCP sequence number (ISN) that a serve.pdf
Guessing or knowing the initial TCP sequence number (ISN) that a serve.pdfGuessing or knowing the initial TCP sequence number (ISN) that a serve.pdf
Guessing or knowing the initial TCP sequence number (ISN) that a serve.pdf
 
Given the following XML fragment- what XPath expression would select a.pdf
Given the following XML fragment- what XPath expression would select a.pdfGiven the following XML fragment- what XPath expression would select a.pdf
Given the following XML fragment- what XPath expression would select a.pdf
 
Greener Pastures Corporation borrowed $1-100-000 on November 1- 2021-.pdf
Greener Pastures Corporation borrowed $1-100-000 on November 1- 2021-.pdfGreener Pastures Corporation borrowed $1-100-000 on November 1- 2021-.pdf
Greener Pastures Corporation borrowed $1-100-000 on November 1- 2021-.pdf
 
Given the following for the Titan Company- the company began operation.pdf
Given the following for the Titan Company- the company began operation.pdfGiven the following for the Titan Company- the company began operation.pdf
Given the following for the Titan Company- the company began operation.pdf
 
Given the following errors and class in Java- How are these errors fix.pdf
Given the following errors and class in Java- How are these errors fix.pdfGiven the following errors and class in Java- How are these errors fix.pdf
Given the following errors and class in Java- How are these errors fix.pdf
 
Given the following class in Java- public class ThreeTenDynArray-T- {.pdf
Given the following class in Java-  public class ThreeTenDynArray-T- {.pdfGiven the following class in Java-  public class ThreeTenDynArray-T- {.pdf
Given the following class in Java- public class ThreeTenDynArray-T- {.pdf
 
Given Information #1- Period 1 is when Devah is working and earning mo.pdf
Given Information #1- Period 1 is when Devah is working and earning mo.pdfGiven Information #1- Period 1 is when Devah is working and earning mo.pdf
Given Information #1- Period 1 is when Devah is working and earning mo.pdf
 
Give concise and substantial answers by relating your answers to your.pdf
Give concise and substantial answers by relating your answers to your.pdfGive concise and substantial answers by relating your answers to your.pdf
Give concise and substantial answers by relating your answers to your.pdf
 
Given a stream of strings- remove all empty strings- import java-uti.pdf
Given a stream of strings- remove all empty strings-   import java-uti.pdfGiven a stream of strings- remove all empty strings-   import java-uti.pdf
Given a stream of strings- remove all empty strings- import java-uti.pdf
 
Given an IntNode struct and the operating functions for a linked list-.pdf
Given an IntNode struct and the operating functions for a linked list-.pdfGiven an IntNode struct and the operating functions for a linked list-.pdf
Given an IntNode struct and the operating functions for a linked list-.pdf
 

Recently uploaded

How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17Celine George
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMELOISARIVERA8
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesPooky Knightsmith
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppCeline George
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxneillewis46
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesAmanpreetKaur157993
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptxPoojaSen20
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnershipsexpandedwebsite
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportDenish Jangid
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxCeline George
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismDabee Kamal
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....Ritu480198
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhleson0603
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...EADTU
 

Recently uploaded (20)

How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 

GLA-01- Java- Big O and Lists Overview and Submission Requirements You.pdf

  • 1. GLA-01: Java, Big O and Lists Overview and Submission Requirements Your task is to work individually to create a series of methods that can solve tech interview questions, as well as analyze the computational complexity of these solutions. You should complete your entire lab in a single file named InterviewQuestions.java. Once you have completed the lab, you should submit InterviewQuestions.java to D2L. External Resources and Code As per the Academic Integrity guidelines, you may not copy code (even with modification) from anywhere, including the internet, other students, or your textbook. You may not consult other students or look at their code. You may not share your code with other students. Any submission that violates the academic honesty guidelines will receive an automatic 0 and will be considered an academic honesty violation. Background: Tech Interviews Technical interviews are a common part of the hiring process in the software development field. Although they can range in format, one of the most common techniques is to ask candidates to solve a couple of programming problems on a whiteboard and then explain their solutions. This GLA takes the form of a number of small programming problems that could appear in such an interview. For each problem, implement the method in InterviewQuestions.java, explain what n is, and state the Big(O) complexity of your solution. Problem One: Pricey Neighbours Suppose you have an array of doubles that represents the value of each house on a long block of houses. Find the three adjacent houses that have the largest combined value, and return the smallest index of the array (leftmost house). Your solution should be of the form: (Note: you may use the provided template) public int findPriceyNeighbours(double[] prices) The method header should state what n is (Java Commented form), and what the Big(O) complexity of your solution is. Problem Two: Common Friends Suppose you have two ArrayLists, each of which represents the friends of a single person. Write a method to find the common friends between those two people-- that is, a list of Strings that appear in both input lists.
  • 2. Your solution should be of the form: (Note: you may use the provided template) public ArrayList<String> commonFriends(ArrayList<String> friendListOne, ArrayList<String> friendListTwo) The method header should state what n is (Java Commented form), and what the Big(O) complexity of your solution is. Problem Three: Count Divisors (Note: you may use the provided template) Suppose you have an array of integers. Count each pair of indices in that array in which the value at the first index is evenly divisible by the values at the following indices. Your solution should be of the form: public int countDivisors(int[] values) The method header should state what n is (Java Commented form), and what the Big(O) complexity of your solution is. Problem Four: First Odd Number Suppose you have an array of integers. All of the integers from indexes 0 up to (But not including) a target index are even. All integers from that target index onwards are odd. Given such an array, find the index of the first odd number. Your solution should be of the form: (Note: you may use the provided template) public int findIndexOfFirstOddNumber(int[] numbers) The method header should state what n is (Java Commented form), and what the Big(O) complexity of your solution is. I have a starter code: do not change anything on the second file of code: FIRST file would be named InterviewQuestions.java: import java.util.ArrayList; public class InterviewQuestions { public int findPriceyNeighbours(double[] prices) { //ToDo return -1;
  • 3. } public ArrayList<String> commonFriends(ArrayList<String> friendListOne, ArrayList<String> friendListTwo) { ArrayList<String> common=new ArrayList<String>(); //ToDo return common; } public int countDivisors(int[] values) { //ToDo return -1; } public int findIndexOfFirstOddNumber(int[] numbers) { //ToDo return -1; } } SECOND FILE named InterviewQuestionsTest.java(DO NOT CHANGE ANYTHING) import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Random;
  • 4. public class InterviewQuestionsTest { private static Random r; static { r=new Random(2); } public static int [] GetRandomArray(int n, int min, int max) { int []a=new int[n]; for(int i=0; i<a.length; i++) { a[i]=r.nextInt(max-min+1)+min; } return a; } public static void displayDoubleArray(double []a) { for(int i=0; i<a.length; i++) { System.out.printf("%.2fn",a[i]); } } public static void displayIntArray(int []a)
  • 5. { for(int i=0; i<a.length; i++) { System.out.print(a[i]+" "); } } public static ArrayList<String> getNRandomNames(int n, ArrayList<String>nameList) { ArrayList<String> friendList=new ArrayList<String>(); for(int i=0; i<n; i++) { friendList.add(nameList.get(r.nextInt(nameList.size()))); } return friendList; } public static void displayNames(String name, ArrayList<String>nameList) { System.out.print(name+"'s Friend List: "); for(var n : nameList) { System.out.print(n+", "); } System.out.println();
  • 6. } public static void makeEvenAllThenOddAll(int []numbers, int pos) { for(int i=0; i<pos; i++) { if(numbers[i]%2==1) { numbers[i]++; } } for(int i=pos; i<numbers.length; i++) { if(numbers[i]%2==0) { numbers[i]++; } } } public static void main(String[] args) { // TODO Auto-generated method stub InterviewQuestions solution=new InterviewQuestions(); int n=10; double []HousePrice= Arrays.stream(GetRandomArray(n, 500000, 1000000)).asDoubleStream().toArray();
  • 7. System.out.println("Problem One: Pricey Neighbours"); System.out.println("House Prices: "); displayDoubleArray(HousePrice); System.out.println("First index of Pricey Neighbours is: "+ solution.findPriceyNeighbours(HousePrice)); System.out.println("nProblem Two: Common Friends"); ArrayList<String>nameList= new ArrayList<>(List.of( "Liam", "Noah", "Oliver", "William","Elijah","James","Benjamin","Lucas","Mason","Ethan","Alexander","Henry","Jacob" ,"Michael", "Daniel", "Logan","Jackson","Sebastian","Jack","Aiden","Owen","Samuel","Matthew","Joseph","Levi"," Mateo","David","John","Wyatt")); ArrayList<String> davidsFriends=getNRandomNames(10,nameList); displayNames("David", davidsFriends); ArrayList<String> susansFriends=getNRandomNames(10,nameList); displayNames("Susan", susansFriends); ArrayList<String> commonFriends=solution.commonFriends(davidsFriends, susansFriends); displayNames("Common Friends", commonFriends); System.out.println("nProblem Three: Count Divisors"); n=6; int []values=GetRandomArray(n, 5, 20); displayIntArray(values); System.out.println("nCount: "+solution.countDivisors(values)); n=10; System.out.println("nProblem Four: First Odd Number");
  • 8. int []numbers=GetRandomArray(n, 10, 50); makeEvenAllThenOddAll(numbers, r.nextInt(n)); displayIntArray(numbers); System.out.println("nFirst odd number's index is: "+solution.findIndexOfFirstOddNumber(numbers)); } } /*If you have implemented your GLA correctly, the following will be your program's output: Problem One: Pricey Neighbours House Prices: 622968.00 520112.00 840169.00 925050.00 916256.00 909680.00 650372.00 979577.00 656166.00 891104.00 First index of Pricey Neighbours is: 3 Problem Two: Common Friends David's Friend List: Jacob, Benjamin, Joseph, Owen, Michael, Lucas, Wyatt, Owen, Jacob, Alexander,
  • 9. Susan's Friend List: Jack, Alexander, Samuel, Henry, Daniel, Logan, Joseph, Benjamin, Sebastian, Wyatt, Common Friends's Friend List: Benjamin, Joseph, Wyatt, Alexander, Problem Three: Count Divisors 10 13 20 15 13 10 Count: 3 Problem Four: First Odd Number 16 20 40 12 35 19 23 31 35 11 First odd number's index is: 4 */