Quick Overview

These questions evaluate algorithmic problem-solving skills: the first focuses on greedy scheduling and time-step simulation to maximize actions before deadlines while the second tests event aggregation, sorting and grouping logic for sessionization.

Compute max planes shot and session count

Company: Supio

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

## Problem 1: Max planes you can shoot before any lands You are given two equal-length arrays: - `altitude[i]`: the initial altitude of plane `i` (positive integer) - `descent[i]`: the amount plane `i` descends per second (positive integer) Time proceeds in whole seconds. At each second `t = 0, 1, 2, ...` you may **shoot down at most one plane instantly** (before it descends for that second). After your shot (or if you skip), **all remaining planes descend by their `descent` value** for that second. A plane **lands successfully** if its altitude becomes `<= 0` after descending at the end of some second. If **any** plane lands, the process stops immediately. **Task:** Assuming you choose the best possible plane to shoot each second, return the **maximum number of planes** you can shoot down **before the first successful landing occurs**. **Input:** `altitude[]`, `descent[]` (same length `n`) **Output:** integer (max planes shot) --- ## Problem 2: Count user sessions from events You are given: - `events`: a list of pairs `[userId, time]` (times are integers; events may be in arbitrary order) - `timeout`: a non-negative integer For each user, sort that user’s events by `time`. Two consecutive events for the **same user** belong to the **same session** if their time difference is `<= timeout`. Otherwise, the later event starts a **new session**. **Task:** Return the **total number of sessions across all users**. **Input:** `events = [[userId, time], ...]`, `timeout` **Output:** integer (number of sessions)

Overview: These questions evaluate algorithmic problem-solving skills: the first focuses on greedy scheduling and time-step simulation to maximize actions before deadlines while the second tests event aggregation, sorting and grouping logic for sessionization.

Maximum Planes Shot Before Landing

At each whole second t starting at 0, shoot at most one plane before remaining planes descend. Return the maximum number shot before any unshot plane lands.

Constraints

  • altitude and descent have the same length
  • All altitudes and descents are positive

Examples

Input: ([1, 3, 4], [1, 1, 1])

Expected Output: 3

Input: ([1, 1, 2], [1, 1, 1])

Expected Output: 1

Hints

  1. Sort planes by their landing deadline ceil(altitude/descent).

Count User Sessions from Events

Group events by user, sort each user by time, and count a new session when the gap between consecutive events is greater than timeout.

Constraints

  • Events may arrive in arbitrary order
  • timeout is non-negative

Examples

Input: ([['u1', 1], ['u1', 3], ['u2', 2], ['u1', 10]], 3)

Expected Output: 3

Input: ([], 5)

Expected Output: 0

Hints

  1. Session rules apply only within the same user.

Maximum Planes Shot Before Landing

Part 1: MediumSupioSoftware Engineer

At each whole second t starting at 0, shoot at most one plane before remaining planes descend. Return the maximum number shot before any unshot plane lands.

View full question (all parts)

Problem 1: Max planes you can shoot before any lands

You are given two equal-length arrays:

  • altitude[i]: the initial altitude of plane i (positive integer)
  • descent[i]: the amount plane i descends per second (positive integer)

Time proceeds in whole seconds. At each second t = 0, 1, 2, ... you may shoot down at most one plane instantly (before it descends for that second). After your shot (or if you skip), all remaining planes descend by their descent value for that second.

A plane lands successfully if its altitude becomes <= 0 after descending at the end of some second.

If any plane lands, the process stops immediately.

Task: Assuming you choose the best possible plane to shoot each second, return the maximum number of planes you can shoot down before the first successful landing occurs.

Input: altitude[], descent[] (same length n)

Output: integer (max planes shot)


Problem 2: Count user sessions from events

You are given:

  • events: a list of pairs [userId, time] (times are integers; events may be in arbitrary order)
  • timeout: a non-negative integer

For each user, sort that user’s events by time. Two consecutive events for the same user belong to the same session if their time difference is <= timeout. Otherwise, the later event starts a new session.

Task: Return the total number of sessions across all users.

Input: events = [[userId, time], ...], timeout

Output: integer (number of sessions)

Examples

Example 1
Input
([1, 3, 4], [1, 1, 1])
Output
3
Example 2
Input
([1, 1, 2], [1, 1, 1])
Output
1

Constraints

  • •altitude and descent have the same length
  • •All altitudes and descents are positive

Comments (0)

No comments yet. Be the first to comment!

Submit your answer

Approved first answer today earns 30 XP
Bold⌘BItalic⌘IInline code⌘`Bullet listTab to nest (○ ■)Numbered listTab to nest (a. i.)QuoteCode block
Formatting help
Language
Case 1
Input
([1, 3, 4], [1, 1, 1])
Expected
3
Case 2
Input
([1, 1, 2], [1, 1, 1])
Expected
1

Browse More Questions