PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This set of four problems evaluates core algorithmic competencies including array manipulation and counting in sorted arrays, resource-constrained optimization for reachability with recharge stations, grid-based connected-component identification, and detection of longest consecutive-value sequences, emphasizing data-structure selection, edge-case reasoning, and time/space complexity analysis. Commonly asked in Coding & Algorithms interviews to assess both conceptual understanding of algorithmic paradigms and practical application of efficient techniques under constraints, these questions measure algorithmic thinking, complexity analysis, and problem decomposition.

  • easy
  • Meta
  • Coding & Algorithms
  • Software Engineer

Solve four OA coding problems

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: HR Screen

The online assessment reportedly contained four coding problems: 1. **Compare negative and positive counts** Given a sorted integer array `nums` in nondecreasing order, return the larger of: - the number of elements less than `0` - the number of elements greater than `0` Elements equal to `0` should not be counted in either group. 2. **Reach a destination with charging stations** A drone must travel `target` units of distance. It starts with `startCharge` units of battery, and it consumes `1` unit of battery per unit of distance traveled. Along the route, `stations[i] = [position_i, charge_i]` describes a charging station at distance `position_i` from the start that can provide `charge_i` additional battery units. The stations are sorted by position. Return the minimum number of charging stops needed to reach the destination, or `-1` if the destination cannot be reached. 3. **Count objects placed on a grid** You are given an `m x n` grid of characters `'X'` and `'.'`. Each object is formed by one or more contiguous `'X'` cells placed either horizontally in one row or vertically in one column. Different objects are separated by at least one `'.'` cell, so no two distinct objects touch horizontally or vertically. Return the total number of objects in the grid. 4. **Find the longest consecutive-value run** Given an unsorted integer array `nums`, return the length of the longest set of consecutive integer values that appears in the array. The values do not need to be adjacent in the original array. Aim for an `O(n)` solution.

Quick Answer: This set of four problems evaluates core algorithmic competencies including array manipulation and counting in sorted arrays, resource-constrained optimization for reachability with recharge stations, grid-based connected-component identification, and detection of longest consecutive-value sequences, emphasizing data-structure selection, edge-case reasoning, and time/space complexity analysis. Commonly asked in Coding & Algorithms interviews to assess both conceptual understanding of algorithmic paradigms and practical application of efficient techniques under constraints, these questions measure algorithmic thinking, complexity analysis, and problem decomposition.

Part 1: Compare Negative and Positive Counts

Given an integer array nums sorted in nondecreasing order, return the larger of the number of negative values and the number of positive values. Values equal to 0 are ignored.

Constraints

  • 0 <= len(nums) <= 100000
  • -100000 <= nums[i] <= 100000
  • nums is sorted in nondecreasing order

Examples

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

Expected Output: 3

Explanation: There are 3 negative values and 3 positive values, so the answer is 3.

Input: ([-3, -2, -1, 0, 0, 1, 2],)

Expected Output: 3

Explanation: There are 3 negative values and 2 positive values.

Input: ([0, 0, 0],)

Expected Output: 0

Explanation: Zeros are ignored, so both counts are 0.

Input: ([-5],)

Expected Output: 1

Explanation: The single element is negative.

Input: ([],)

Expected Output: 0

Explanation: An empty array has no negative or positive values.

Hints

  1. Because the array is sorted, all negative numbers appear before all zeros and positive numbers.
  2. Use binary search to find the first 0 and the first value greater than 0.

Part 2: Reach a Destination with Charging Stations

A drone must travel target units of distance. It starts with startCharge units of battery and consumes 1 unit of battery per unit of distance. Along the route, stations[i] = [position_i, charge_i] gives a charging station at position_i that can add charge_i battery units. The stations are sorted by position. Return the minimum number of charging stops needed to reach the destination, or -1 if it is impossible.

Constraints

  • 0 <= target <= 1000000000
  • 0 <= startCharge <= 1000000000
  • 0 <= len(stations) <= 100000
  • 0 <= position_i <= target
  • 0 <= charge_i <= 1000000000
  • stations is sorted by position_i in nondecreasing order

Examples

Input: (100, 10, [[10, 60], [20, 30], [30, 30], [60, 40]])

Expected Output: 2

Explanation: Stop at position 10 for 60 charge, then later use the station at position 60 for 40 charge.

Input: (100, 50, [[25, 25], [50, 50]])

Expected Output: 1

Explanation: The drone can reach position 50, then one charge of 50 is enough to reach target.

Input: (1, 1, [])

Expected Output: 0

Explanation: The starting charge is already enough.

Input: (100, 1, [[10, 100]])

Expected Output: -1

Explanation: The first station is too far away to reach.

Input: (10, 0, [[0, 5], [5, 5]])

Expected Output: 2

Explanation: The drone starts at a station at position 0, charges there, then charges again at position 5.

Hints

  1. As you move as far as possible, keep track of all stations you have already passed but not used.
  2. When you cannot go farther, choose the passed station with the largest available charge.

Part 3: Count Objects Placed on a Grid

You are given an m x n grid of characters 'X' and '.'. Each object is made of one or more contiguous 'X' cells arranged either horizontally in one row or vertically in one column. Different objects are separated by at least one '.' cell, so no two distinct objects touch horizontally or vertically. Return the total number of objects in the grid.

Constraints

  • 0 <= m <= 500
  • 0 <= n <= 500
  • grid contains only 'X' and '.'
  • All rows have the same length
  • Each object is a straight horizontal or vertical group of 'X' cells
  • No two distinct objects touch horizontally or vertically

Examples

Input: ([],)

Expected Output: 0

Explanation: An empty grid has no objects.

Input: (['XX..', '....', '..X.', '..X.'],)

Expected Output: 2

Explanation: There is one horizontal object in the first row and one vertical object in the last column area.

Input: (['X.X', '...', 'XXX'],)

Expected Output: 3

Explanation: There are two single-cell objects in the first row and one horizontal object in the last row.

Input: (['...', '...'],)

Expected Output: 0

Explanation: There are no 'X' cells.

Input: (['X'],)

Expected Output: 1

Explanation: A single 'X' cell is one object.

Hints

  1. Instead of exploring every full object, count only the first cell of each object.
  2. An 'X' cell starts a new object if there is no 'X' directly above it and no 'X' directly to its left.

Part 4: Find the Longest Consecutive-Value Run

Given an unsorted integer array nums, return the length of the longest set of consecutive integer values that appears in the array. The values do not need to be adjacent in the original array, and duplicates should not increase the length. Aim for an O(n) solution.

Constraints

  • 0 <= len(nums) <= 100000
  • -1000000000 <= nums[i] <= 1000000000
  • nums may contain duplicates
  • The expected solution should run in O(n) average time

Examples

Input: ([100, 4, 200, 1, 3, 2],)

Expected Output: 4

Explanation: The longest consecutive run is 1, 2, 3, 4.

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

Expected Output: 3

Explanation: Duplicates are ignored; the run 0, 1, 2 has length 3.

Input: ([],)

Expected Output: 0

Explanation: An empty array has no consecutive run.

Input: ([5],)

Expected Output: 1

Explanation: A single number forms a run of length 1.

Input: ([-2, -1, 0, 2, 3],)

Expected Output: 3

Explanation: The longest run is -2, -1, 0.

Hints

  1. Use a set so that membership checks are O(1) on average.
  2. Only start counting from a number x if x - 1 is not present.
Last updated: Jun 25, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Find Shortest Unique Prefixes - Meta (medium)
  • Compute Exclusive Execution Times - Meta (medium)
  • Solve Tree Columns And Maze Variants - Meta (medium)
  • Solve Tree Diameter and Palindromic Counts - Meta (medium)
  • Simulate Monster Team Battles - Meta (hard)