<commit_before># from https://www.hackerrank.com/challenges/30-binary-search-trees
# Write a method, Solution#getHeight, that returns the height of a binary tree.

class Node
  attr_accessor :left, :right, :data

  def initialize data
    @left = @right = nil
    @data = data
  end
end

class Solution
  def insert (root,data)
    if root == nil
      return Node.new(data)
    else
      if data <= root.data
        cur = self.insert(root.left, data)
        root.left = cur
      else
        cur = self.insert(root.right, data)
        root.right = cur
      end
    end
    return root
  end

  def getHeight(root)
    #Write your code here
  end
end

# Runner code
myTree = Solution.new
root = nil
input = [7, 3, 5, 2, 1, 4, 6, 7]
T = input.shift.to_i

for i in 1..T
  data = input.shift.to_i
  root = myTree.insert(root,data)
end

height = myTree.getHeight(root)
puts "Your solution works: #{height == 3}"<commit_msg>Add working solution to binary_tree.rb<commit_after># from https://www.hackerrank.com/challenges/30-binary-search-trees
# Write a method, Solution#getHeight, that returns the height of a binary tree.

class Node
  attr_accessor :left, :right, :data

  def initialize data
    @left = @right = nil
    @data = data
  end
end

class Solution
  def insert (root, data)
    if root == nil
      return Node.new(data)
    else
      if data <= root.data
        cur = self.insert(root.left, data)
        root.left = cur
      else
        cur = self.insert(root.right, data)
        root.right = cur
      end
    end
    return root
  end

  def getHeight(root)
    result = [0, 0]
    if root.left
      result[0] += 1 + getHeight(root.left)
    end
    if root.right
      result[1] += 1 + getHeight(root.right)
    end
    return result.max
  end
end

# Runner code
myTree = Solution.new
root = nil
input = [7, 3, 5, 2, 1, 4, 6, 7]
T = input.shift.to_i

for i in 1..T
  data = input.shift.to_i
  root = myTree.insert(root,data)
end

height = myTree.getHeight(root)
puts "Your solution works: #{height == 3}"
{'fraction_non_alphanumeric': 0.10875984251968504, 'fraction_numerical': 0.014763779527559055, 'mean_word_length': 2.529513888888889, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7222306', 'n_tokens_mistral': 734, 'n_tokens_neox': 700, 'n_words': 223}