This solution is generated by ChatGPT, correctness is not guaranteed.

AI solution for JavaScript Coding Question on BFE.dev
91. invert a binary tree

Yes, being able to invert a binary tree is a common coding question in technical interviews, including those at Google. Here's an example solution in JavaScript:

function invertTree(root) {
  if (!root) {
    return null;
  }
  
  const temp = root.left;
  root.left = invertTree(root.right);
  root.right = invertTree(temp);
  
  return root;
}

This function takes in the root of a binary tree and recursively swaps the left and right children of each node. It returns the new root of the inverted tree.

It's worth noting that while this question is often asked in interviews, it's not necessarily a reflection of the types of problems you would solve on a day-to-day basis as a software engineer. Nevertheless, it's a valuable exercise in algorithmic thinking and can help demonstrate your ability to work with trees and recursion.