Browser tab content: Problem List
0
Debugging...
Run
Submit
00:00:00
Description
Editorial
Editorial
Solutions
Solutions
Submissions
Submissions
Code
Note
Note
Testcase
Testcase
Test Result
401. Binary Watch
Easy
Topics
Companies
Hint

A binary watch has 4 LEDs on the top to represent the hours (0-11), and 6 LEDs on the bottom to represent the minutes (0-59). Each LED represents a zero or one, with the least significant bit on the right.

For example, the below binary watch reads "4:51".

Given an integer turnedOn which represents the number of LEDs that are currently on (ignoring the PM), return all possible times the watch could represent. You may return the answer in any order.

The hour must not contain a leading zero.

For example, "01:00" is not valid. It should be "1:00".

The minute must consist of two digits and may contain a leading zero.

For example, "10:2" is not valid. It should be "10:02".

 

Example 1:

Input: turnedOn = 1
Output: ["0:01","0:02","0:04","0:08","0:16","0:32","1:00","2:00","4:00","8:00"]


Example 2:

Input: turnedOn = 9
Output: []


 

Constraints:

0 <= turnedOn <= 10
Seen this question in a real interview before?
1/5
Yes
No
Accepted
153K
Submissions
276.5K
Acceptance Rate
55.3%
Topics
Backtracking
Bit Manipulation
Companies
0 - 6 months
Google
2
6 months ago
Amazon
3
Uber
3
Adobe
2
Hint 1
Simplify by seeking for solutions that involve comparing bit counts.
Hint 2
Consider calculating all possible times for comparison purposes.
Similar Questions
Letter Combinations of a Phone Number
Medium
Number of 1 Bits
Easy
Discussion (54)
Choose a type
Preview
Comment
💡 Discussion Rules

1. Please don't post any solutions in this discussion.

2. The problem discussion is for asking questions about the problem or for sharing tips - anything except for solutions.

3. If you'd like to share your solution for feedback and ideas, please head to the solutions tab and post it there.

Sort by:Best
No comments yet.
1
2
3
4
5
6
Copyright ©️ 2024 LeetCode All rights reserved
1.4K
54
Java
Auto
1
2
3
4
5
class Solution {
    public List<String> readBinaryWatch(int turnedOn) {
        
    }
}
Saved
Ln 1, Col 1
You must run your code first

Word Squares - LeetCode

Problem List
Tag
327. Count of Range Sum

Hard

328. Odd Even Linked List

Med.

329. Longest Increasing Path in a Matrix

Hard

330. Patching Array

Hard

331. Verify Preorder Serialization of a Binary Tree

Med.

332. Reconstruct Itinerary

Hard

333. Largest BST Subtree

Med.

334. Increasing Triplet Subsequence

Med.

335. Self Crossing

Hard

336. Palindrome Pairs

Hard

337. House Robber III

Med.

338. Counting Bits

Easy

339. Nested List Weight Sum

Med.

340. Longest Substring with At Most K Distinct Characters

Med.

341. Flatten Nested List Iterator

Med.

342. Power of Four

Easy

343. Integer Break

Med.

344. Reverse String

Easy

345. Reverse Vowels of a String

Easy

346. Moving Average from Data Stream

Easy

347. Top K Frequent Elements

Med.

348. Design Tic-Tac-Toe

Med.

349. Intersection of Two Arrays

Easy

350. Intersection of Two Arrays II

Easy

351. Android Unlock Patterns

Med.

352. Data Stream as Disjoint Intervals

Hard

353. Design Snake Game

Med.

354. Russian Doll Envelopes

Hard

355. Design Twitter

Med.

356. Line Reflection

Med.

357. Count Numbers with Unique Digits

Med.

358. Rearrange String k Distance Apart

Hard

359. Logger Rate Limiter

Easy

360. Sort Transformed Array

Med.

361. Bomb Enemy

Med.

362. Design Hit Counter

Med.

363. Max Sum of Rectangle No Larger Than K

Hard

364. Nested List Weight Sum II

Med.

365. Water and Jug Problem

Med.

366. Find Leaves of Binary Tree

Med.

367. Valid Perfect Square

Easy

368. Largest Divisible Subset

Med.

369. Plus One Linked List

Med.

370. Range Addition

Med.

371. Sum of Two Integers

Med.

372. Super Pow

Med.

373. Find K Pairs with Smallest Sums

Med.

374. Guess Number Higher or Lower

Easy

375. Guess Number Higher or Lower II

Med.

376. Wiggle Subsequence

Med.

377. Combination Sum IV

Med.

378. Kth Smallest Element in a Sorted Matrix

Med.

379. Design Phone Directory

Med.

380. Insert Delete GetRandom O(1)

Med.

381. Insert Delete GetRandom O(1) - Duplicates allowed

Hard

382. Linked List Random Node

Med.

383. Ransom Note

Easy

384. Shuffle an Array

Med.

385. Mini Parser

Med.

386. Lexicographical Numbers

Med.

387. First Unique Character in a String

Easy

388. Longest Absolute File Path

Med.

389. Find the Difference

Easy

390. Elimination Game

Med.

391. Perfect Rectangle

Hard

392. Is Subsequence

Easy

393. UTF-8 Validation

Med.

394. Decode String

Med.

395. Longest Substring with At Least K Repeating Characters

Med.

396. Rotate Function

Med.

397. Integer Replacement

Med.

398. Random Pick Index

Med.

399. Evaluate Division

Med.

400. Nth Digit

Med.

401. Binary Watch

Easy

402. Remove K Digits

Med.

403. Frog Jump

Hard

404. Sum of Left Leaves

Easy

405. Convert a Number to Hexadecimal

Easy

406. Queue Reconstruction by Height

Med.

407. Trapping Rain Water II

Hard

408. Valid Word Abbreviation

Easy

409. Longest Palindrome

Easy

410. Split Array Largest Sum

Hard

411. Minimum Unique Word Abbreviation

Hard

412. Fizz Buzz

Easy

413. Arithmetic Slices

Med.

414. Third Maximum Number

Easy

415. Add Strings

Easy

416. Partition Equal Subset Sum

Med.

417. Pacific Atlantic Water Flow

Med.

418. Sentence Screen Fitting

Med.

419. Battleships in a Board

Med.

420. Strong Password Checker

Hard

421. Maximum XOR of Two Numbers in an Array

Med.

422. Valid Word Square

Easy

423. Reconstruct Original Digits from English

Med.

424. Longest Repeating Character Replacement

Med.

425. Word Squares

Hard

426. Convert Binary Search Tree to Sorted Doubly Linked List

Med.

427. Construct Quad Tree

Med.

428. Serialize and Deserialize N-ary Tree

Hard

429. N-ary Tree Level Order Traversal

Med.

430. Flatten a Multilevel Doubly Linked List

Med.

431. Encode N-ary Tree to Binary Tree

Hard

432. All O`one Data Structure

Hard

433. Minimum Genetic Mutation

Med.

434. Number of Segments in a String

Easy

435. Non-overlapping Intervals

Med.

436. Find Right Interval

Med.

437. Path Sum III

Med.

438. Find All Anagrams in a String

Med.

439. Ternary Expression Parser

Med.

440. K-th Smallest in Lexicographical Order

Hard

441. Arranging Coins

Easy

442. Find All Duplicates in an Array

Med.

443. String Compression

Med.

444. Sequence Reconstruction

Med.

445. Add Two Numbers II

Med.

446. Arithmetic Slices II - Subsequence

Hard

447. Number of Boomerangs

Med.

448. Find All Numbers Disappeared in an Array

Easy

449. Serialize and Deserialize BST

Med.

450. Delete Node in a BST

Med.

451. Sort Characters By Frequency

Med.

452. Minimum Number of Arrows to Burst Balloons

Med.

453. Minimum Moves to Equal Array Elements

Med.

454. 4Sum II

Med.

455. Assign Cookies

Easy

456. 132 Pattern

Med.

457. Circular Array Loop

Med.

458. Poor Pigs

Hard

459. Repeated Substring Pattern

Easy

460. LFU Cache

Hard

461. Hamming Distance

Easy

462. Minimum Moves to Equal Array Elements II

Med.

463. Island Perimeter

Easy

464. Can I Win

Med.

465. Optimal Account Balancing

Hard

466. Count The Repetitions

Hard

467. Unique Substrings in Wraparound String

Med.

468. Validate IP Address

Med.

469. Convex Polygon

Med.

470. Implement Rand10() Using Rand7()

Med.

471. Encode String with Shortest Length

Hard

472. Concatenated Words

Hard

473. Matchsticks to Square

Med.

474. Ones and Zeroes

Med.

475. Heaters

Med.

476. Number Complement

Easy

Remove distracting text, extract the programming question, provide simple, common, and optimized Java solution for it.