Coder Social home page Coder Social logo

practice-for-week-05-array-long-practice's Introduction

Array Practice Problems

Implement the following problems. The skeleton code is provided to you in array-practice.js

While doing the problems, make sure to recite out loud and write in comments the time complexities of any Array operations you use. Evaluate the time and space complexities of each problem after you finish them. Ask yourself if the problem's time and space complexities can be further optimized.

Find Minimum

Given an Array of numbers, return the smallest number in the array. Do this in O(n) Time.

Example:

const arr = [7, 5, 2, 3, 4, 1]; 
findMinimum(arr); // => 1

Running Sum of Array

Given an array of numbers, return the running sum of its elements.

Example:

const arr = [1,2,3,4]; 
runningSum(arr); // => [1,3,6,10]

Even Number of Characters

Given an array of strings, return the number of strings with an even number of characters

Example:

const arr = ['ab', 'abc', 'a', 'abcd']; 
evenNumOfChars(arr); // => 2

How many numbers smaller than current number

Given an array of numbers, return a new array containing the number of elements smaller than the current element at each position.

Example:

const arr = [8,1,2,2,3];
smallerThanCurr(arr); // => [4,0,1,1,3]

Two Sum

Given an array of numbers and a target sum, your function should return a boolean value (true or false) if there are two elements in the array that add up to the target value.

Example:

const arr = [4, 2, 3, 6, 9]; 
twoSum(arr, 10); // => True

const arr2 = [4, 2, 3, 6, 9];
twoSum(arr2, 16); // => False

Find Second Largest

Given an array of numbers, return the second largest number in the array.

Example:

const arr = [4, 2, 3, 6, 8];
secondLargest(arr); // => 6

Shuffle The Array

Given an array, return an array containing those elements in random order.

Your function should return a new array and NOT mutate the original.

Hint: Look up Math.random() on MDN.

Example:

const arr = [2, 5, 1, 3, 4, 7];
shuffle(arr); // => [2, 3, 5, 4, 1, 7] 

practice-for-week-05-array-long-practice's People

Contributors

3alifaisal avatar aa-assessment-project-manager[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.