Problem 1035. Generate a vector like 1,2,2,3,3,3,4,4,4,4
Generate a vector like 1,2,2,3,3,3,4,4,4,4
So if n = 3, then return
[1 2 2 3 3 3]
And if n = 5, then return
[1 2 2 3 3 3 4 4 4 4 5 5 5 5 5]
Solution Stats
Problem Comments
-
29 Comments
Show
26 older comments
Christian Schröder
on 30 Sep 2024
@Long Runjia Yu Perhaps look at other (correct) solutions to this problem, and learn from them.
Here (and elsewhere) one way to solve the problem at hand is to generate more than you need, and then throw away that which is superfluous (both without loops).
Robert
on 19 Nov 2024
Very interesting
Vaishnavi Devi
on 4 Jun 2025
given an idea guys
Solution Comments
Show commentsProblem Recent Solvers12607
Suggested Problems
-
667 Solvers
-
385 Solvers
-
1170 Solvers
-
7871 Solvers
-
495 Solvers
More from this Author17
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!