Problem 112. Remove the air bubbles
Given a matrix a, return a matrix b in which all the zeros have "bubbled" to the top. That is, any zeros in a given column should be moved to the top. The order of the remaining nonzero numbers in the column should be preserved.
Example 1
Input a = [ 1 2 3
0 4 5
6 0 0 ] Output b is [ 0 0 0
1 2 3
6 4 5 ]Example 2
Input a = [ 1 0 5 0 6 0 7 ]' Output b is [ 0 0 0 1 5 6 7 ]'
Example 3
Input a = [ 1 0
1 1 ]
Output b is [ 1 0
1 1 ]
Solution Stats
Problem Comments
-
5 Comments
Show
2 older comments
Chien-Han Su
on 2 Nov 2020
love this one
Jakeb Chouinard
on 20 Nov 2020
28 attempts later, we finally made it
CrypticBlue
on 8 Jul 2021
nice question!
Nguyen Viet Dung
on 11 Aug 2021
good problem
Manideep Bharadwaj
on 15 Apr 2023
good analogy
Solution Comments
Show commentsProblem Recent Solvers1316
Suggested Problems
-
Return the 3n+1 sequence for n
8475 Solvers
-
Remove the small words from a list of words.
1558 Solvers
-
1230 Solvers
-
831 Solvers
-
ベクトル [1 2 3 4 5 6 7 8 9 10] の作成
588 Solvers
More from this Author51
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!