wtmhahagd

problemy Krzysztofa

Nov 27th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. 1)
  2.  
  3. Write a function that, given the root node of a binary tree (not a binary search tree, heap, etc.!), removes all subtrees of the binary tree that consist of all zeros, and returns the root node of the (modified) binary tree.
  4.  
  5. example:
  6. root root
  7. 0 ---> 0
  8. / \ / \
  9. 5 3 5 3
  10. / \ \ \
  11. 0 2 0 2
  12. / \
  13. 0 0
  14. / \
  15. 0 0
  16.  
  17.  
  18. 2)
  19.  
  20. Lowercase Two just acquired another bank. This other bank was one of the first banks to have online banking services, and Lowercase Two has also started their own online banking services. It's time for a merger - what are some technological considerations you'll have to take into account?
  21.  
  22. ==============
  23.  
  24. Here's a function from the online banking services. Documentation is lacking, and we haven't been able to figure out the bank's policies on what makes someone eligible for benefits, either. What does this function do?
  25.  
  26. static boolean isEligibleForBenefits(boolean isOldEnough, boolean hasDebt, boolean accountOldEnough) {
  27. if (accountOldEnough == false) {
  28. if (!hasDebt && isOldEnough) {
  29. return true;
  30. } else if (!hasDebt && accountOldEnough) {
  31. return false;
  32. }
  33. return false;
  34. } else if (!hasDebt) {
  35. if (isOldEnough && accountOldEnough) {
  36. return true;
  37. }
  38. if (!accountOldEnough) {
  39. if (!isOldEnough) {
  40. return false;
  41. }
  42. return false;
  43. }
  44. if (!isOldEnough) {
  45. return false;
  46. }
  47. return true;
  48. }
  49. return false;
  50. }
  51.  
  52. How might you rewrite it?
Add Comment
Please, Sign In to add comment