
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Meeting Rooms 2 problem in JavaScript
We will be given an array of arrays, each subarray consists of exactly two elements indicating the start and end time of a meeting.
The task of our function is to find the maximum number of meetings one person can take avoiding the conflict of time. The function should finally return this number.
For example −
If the input array describing meeting times is −
const arr = [[5, 40], [10, 20], [25, 35]];
Then the output should be −
const output = 2;
because it's not possible to take all three meetings due to overlapping times but [10, 20] and [25, 35] can be attended.
Example
The code for this will be −
const arr = [[5, 40], [10, 20], [25, 35]]; const canAttendAll = (arr = []) => { const times = new Set(); const { length } = arr; for (let i = 0; i < length; i += 1) { for (let j = arr[i][0]; j < arr[i][1]; j += 1) { if (times.has(j)) { return false; } else { times.add(j); }; }; }; return true; }; console.log(canAttendAll(arr));
Output
And the output in the console will be −
false
- Related Articles
- Meeting Rooms II in C++
- 2 Key keyboard problem in JavaScript
- Snail Trail Problem in JavaScript
- Recursive Staircase problem in JavaScript
- Distributing Bananas Problem in JavaScript
- 2-Satisfiability(2-SAT) Problem in C/C++?
- Recursion problem Snail Trail in JavaScript
- Expressive words problem case in JavaScript
- Crack Alphabets fight problem in JavaScript
- Keys and Rooms in Python
- In a hotel, there are four types of rooms: Basic rooms $-80$ ; Superior rooms $-60$ ; Deluxe rooms $-40$ and Family suits $-20$. Draw a pie chart to represent this data.
- Combination sum problem using JavaScript
- Meeting Scheduler in C++
- The algorithm problem - Backtracing pattern in JavaScript
- Two sum problem in linear time in JavaScript

Advertisements