4 kyu
Sort binary tree by levels
913 of 14,541kars7e
Description:
You are given a binary tree:
class TreeNode
attr_accessor :left
attr_accessor :right
attr_reader :value
end
Your task is to return the list with elements from tree sorted by levels, which means the root element goes first, then root children (from left to right) are second and third, and so on.
Return empty array if root is nil
.
Example 1 - following tree:
2
8 9
1 3 4 5
Should return following list:
[2,8,9,1,3,4,5]
Example 2 - following tree:
1
8 4
3 5
7
Should return following list:
[1,8,4,3,5,7]
Trees
Binary Trees
Performance
Algorithms
Sorting
Similar Kata:
Stats:
Created | Dec 28, 2013 |
Published | Dec 28, 2013 |
Warriors Trained | 36139 |
Total Skips | 8459 |
Total Code Submissions | 64203 |
Total Times Completed | 14541 |
Ruby Completions | 913 |
Haskell Completions | 658 |
Python Completions | 6358 |
Groovy Completions | 40 |
C# Completions | 1491 |
Java Completions | 1945 |
JavaScript Completions | 2327 |
λ Calculus Completions | 10 |
C Completions | 573 |
Rust Completions | 549 |
Scala Completions | 40 |
Total Stars | 959 |
% of votes with a positive feedback rating | 93% of 1330 |
Total "Very Satisfied" Votes | 1170 |
Total "Somewhat Satisfied" Votes | 145 |
Total "Not Satisfied" Votes | 15 |