Rocket Academy Bootcamp
  • 🚀Welcome to Bootcamp!
  • 🛠️Logistics
    • Course Schedules
    • Course Methodology
    • Required Software
    • LinkedIn Education Badge
  • 📚General Reference
    • Naming, Casing, and Commenting Conventions
    • VS Code Tips
    • Recommended Resources
  • 🪨0: Foundations
    • 0.1: Command Line
    • 0.2: Git
      • 0.2.1: Branches
    • 0.3: GitHub
      • 0.3.1: Pull Requests
    • 0.4: JavaScript
      • 0.4.1: ES6
      • 0.4.2: Common Syntax
      • 0.4.3: Reference vs Value
      • 0.4.4: Classes
      • 0.4.5: Destructuring and Spread Operator
      • 0.4.6: Promises
        • 0.4.6.1: Async Await
    • 0.5: Node.js
      • 0.5.1: Node Modules
      • 0.5.2: NPM
      • 0.5.3: Nodemon
  • 🖼️1: Frontend
    • 1.1: HTML
    • 1.2: CSS
      • 1.2.1: Layout
    • 1.3: React
      • Styling in ReactJs
      • Using Styling Libraries with React
      • React Deployment
    • 1.E: Exercises
      • 1.E.1: Recipe Site
      • 1.E.2: Portfolio Page
      • 1.E.3: World Clock
      • 1.E.4: High Card
      • 1.E.5: Guess The Word
    • 1.P: Frontend App
  • 🏭2: Full Stack
    • 2.1: Internet 101
      • 2.1.1: Chrome DevTools Network Panel
      • 2.1.2: HTTP Requests and Responses
    • 2.2: Advanced React
      • 2.2.1: AJAX
      • 2.2.2: React Router
      • 2.2.3: useContext
      • 2.2.4: useReducer
      • 2.2.5: Environmental Variables
      • 2.2.6: React useMemo - useCallback
    • 2.3: Firebase
      • 2.3.1: Firebase Realtime Database
      • 2.3.2: Firebase Storage
      • 2.3.3: Firebase Authentication
      • 2.3.4: Firebase Hosting
      • 2.3.5: Firebase Techniques
    • 2.E: Exercises
      • 2.E.1: Weather App
      • 2.E.2: Instagram Chat
      • 2.E.3: Instagram Posts
      • 2.E.4: Instagram Auth
      • 2.E.5: Instagram Routes
    • 2.P: Full-Stack App (Firebase)
  • 🤖3: Backend
    • 3.1: Express.js
      • 3.1.1 : MVC
    • 3.2: SQL
      • 3.2.1: SQL 1-M Relationships
      • 3.2.2: SQL M-M Relationships
      • 3.2.3: SQL Schema Design
      • 3.2.4: Advanced SQL Concepts
      • 3.2.5: SQL - Express
      • 3.2.6: DBeaver
    • 3.3: Sequelize
      • 3.3.1: Sequelize One-To-Many (1-M) Relationships
      • 3.3.2: Sequelize Many-To-Many (M-M) Relationships
      • 3.3.3: Advanced Sequelize Concepts
      • 3.3.4 Database Design
    • 3.4: Authentication
      • 3.4.1: JWT App
    • 3.5: Application Deployment
    • 3.E: Exercises
      • 3.E.1: Bigfoot JSON
      • 3.E.2: Bigfoot SQL
      • 3.E.3: Bigfoot SQL 1-M
      • 3.E.4: Bigfoot SQL M-M
      • 3.E.5: Carousell Schema Design
      • 3.E.6: Carousell Auth
    • 3.P: Full-Stack App (Express)
  • 🏞️4: Capstone
    • 4.1: Testing
      • 4.1.1: Frontend React Testing
      • 4.1.2: Backend Expressjs Testing
    • 4.2: Continuous Integration
      • 4.2.1 Continuous Deployment (Fly.io)
      • 4.2.2: Circle Ci
    • 4.3: TypeScript
    • 4.4: Security
    • 4.5: ChatGPT for SWE
    • 4.6: Soft Skills for SWE
    • 4.P: Capstone
  • 🧮Algorithms
    • A.1: Data Structures
      • A.1.1: Arrays
        • A.1.1.1: Binary Search
        • A.1.1.2: Sliding Windows
      • A.1.2: Hash Tables
      • A.1.3: Stacks
      • A.1.4: Queues
      • A.1.5: Linked Lists
      • A.1.6: Trees
      • A.1.7: Graphs
      • A.1.8: Heaps
    • A.2: Complexity Analysis
    • A.3: Object-Oriented Programming
    • A.4: Recursion
    • A.5: Dynamic Programming
    • A.6: Bit Manipulation
    • A.7: Python
  • 💼Interview Prep
    • IP.1: Job Application Strategy
    • IP.2: Resume
    • IP.3: Portfolio
Powered by GitBook
On this page
  • Learning Objectives
  • Common array functions
  • Exercises
  • Pre-Class
  • Part 1
  • Part 2
  • Part 3
  • More Comfortable
  1. Algorithms
  2. A.1: Data Structures

A.1.1: Arrays

Learning Objectives

  1. Understand common array functions and their use cases

  2. Get familiar with solving algorithm problems with arrays

Common array functions

Assume we start with the following example array arr. Scroll right in the table below to see explanations.

const arr = [2, 1, 3];
Function
Resulting value of `arr`
Return value
Explanation

arr[1]

[2,1,3]

1

We can access value at specific index in array in a single operation

arr.push(4)

[2,1,3,4]

4

We can append to end of array in single operation

arr.length

[2,1,3]

3

JS Array data structure stores up-to-date length that we can retrieve in constant time

Math.max(...arr)

[2,1,3]

3

Get max element of unsorted array requires iterating over every element in array

arr.shift()

[1, 3]

2

Removing element from start of array requires shifting every element to the left by 1 index

arr.unshift(4)

[4,2,1,3]

4

Adding element to start of array requires shifting every element to the right by 1 index

arr.splice(1, 0, 4)

[2,4,1,3]

[2, 4, 4, 1, 3]

Adding and removing elements from the middle of an array requires shifting every following element by a constant number of indexes. The splice command starts at index 1, will not remove any items but insert the value 4

arr.sort()

[1,2,3]

[1,2,3]

The fastest sorting algorithms run in O(nlogn) time, different JS runtimes implement different sorting algorithms that all have similar runtimes.

Exercises

After attempting each problem, find solutions in the Leaderboard tab (HackerRank, may be on left side of page) or Solution or Discuss tabs (LeetCode) on that problem's page. If you get stuck for more than 15 minutes, review and understand the solutions and move on. Come back and re-attempt the problem after a few days.

Pre-Class

Part 1

Part 2

Part 3

    1. Hint: You may find the array sort method helpful to sort input array by word length

    2. Hint: You may find nested for loops helpful where the indexes follow the pattern in the below code sample

Code sample for String Matching in an Array:

for (let i = 0; i <= arr; i += 1) {
  for (let j = i+1; j <= arr; j += 1) {
    // Compare arr[i] and arr[j] without duplicate checks
  }
}

More Comfortable

PreviousA.1: Data StructuresNextA.1.1.1: Binary Search

Last updated 1 year ago

Running Sum of 1D Array ()

Richest Customer Wealth ()

Valid Mountain Array ()

Sherlock and Array ()

Jewels and Stones ()

Missing Numbers ()

Sparse Arrays ()

Count Items Matching a Rule ()

Kids with the Greatest Number of Candies ()

Left Rotation ()

Number of Good Pairs ()

Sort Array by Parity ()

Shuffle the Array ()

String Matching in an Array ()

Ice Cream Parlor ()

Squares of a Sorted Array ()

Sort Array by Parity II ()

Relative Sort Array ()

🧮
LeetCode
LeetCode
LeetCode
HackerRank
LeetCode
HackerRank
HackerRank
LeetCode
LeetCode
HackerRank
LeetCode
LeetCode
LeetCode
LeetCode
Recommended LeetCode solution
HackerRank
LeetCode
LeetCode
LeetCode