`{"id":"9fe0e72a-4b34-4f39-a208-a0ecffa4ab22","name":"Diagonal Order Sum Of A Binary Tree","description":"1. Given a Binary Tree, print Diagonal order sum of it. \r\n2. For more Information watch given video link below.\r\n","inputFormat":"Input is managed for you.\r\n","outputFormat":"Output is managed for you. \r\n","constraints":"0 &lt;= Number of Nodes &lt;= 10^5\r\n-1000 &lt;= value of Node data &lt;= 1000\r\n","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n public static Scanner scn = new Scanner(System.in);\r\n\r\n public static class TreeNode {\r\n int val = 0;\r\n TreeNode left = null;\r\n TreeNode right = null;\r\n\r\n TreeNode(int val) {\r\n this.val = val;\r\n }\r\n }\r\n\r\n public static ArrayList<Integer> diagonalOrderSum(TreeNode root) {\r\n\r\n return null;\r\n }\r\n\r\n // input_section=================================================\r\n\r\n public static TreeNode createTree(int[] arr, int[] IDX) {\r\n if (IDX > arr.length || arr[IDX] == -1) {\r\n IDX++;\r\n return null;\r\n }\r\n TreeNode node = new TreeNode(arr[IDX++]);\r\n node.left = createTree(arr, IDX);\r\n node.right = createTree(arr, IDX);\r\n\r\n return node;\r\n }\r\n\r\n public static void solve() {\r\n int n = scn.nextInt();\r\n int[] arr = new int[n];\r\n for (int i = 0; i < n; i++)\r\n arr[i] = scn.nextInt();\r\n\r\n int[] IDX = new int;\r\n TreeNode root = createTree(arr, IDX);\r\n\r\n ArrayList<Integer> ans = diagonalOrderSum(root);\r\n for (Integer j : ans)\r\n System.out.print(j + \" \");\r\n\r\n }\r\n\r\n public static void main(String[] args) {\r\n solve();\r\n }\r\n}\r\n\r\n"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"15\r\n4\r\n2\r\n1\r\n-1\r\n-1\r\n3\r\n-1\r\n-1\r\n6\r\n5\r\n-1\r\n-1\r\n7\r\n-1\r\n-1","sampleOutput":"17 10 1 ","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"2e9df04c-be14-441c-9a18-8b5a8ca6596d","name":"Trees For Intermediate","slug":"trees-for-intermediate-9994","type":0},{"id":"6e2a3a42-ff94-4557-8e9e-e5cc43a486f0","name":"Diagonal Order Sum Of A Binary Tree","slug":"diagonal-order-sum-of-a-binary-tree","type":1}],"next":{"id":"197416b7-d7a7-4cc4-b324-a0f9e191f855","name":"Diagonal Order Sum of a Binary Tree","type":3,"slug":"diagonal-order-sum-of-a-binary-tree"},"prev":{"id":"067e090f-11c7-4c1d-878d-478de44ff67e","name":"Vertical Order Sum of a Binary Tree","type":3,"slug":"vertical-order-sum-of-a-binary-tree"}}}`

# Diagonal Order Sum Of A Binary Tree

1. Given a Binary Tree, print Diagonal order sum of it. 2. For more Information watch given video link below.

`{"id":"9fe0e72a-4b34-4f39-a208-a0ecffa4ab22","name":"Diagonal Order Sum Of A Binary Tree","description":"1. Given a Binary Tree, print Diagonal order sum of it. \r\n2. For more Information watch given video link below.\r\n","inputFormat":"Input is managed for you.\r\n","outputFormat":"Output is managed for you. \r\n","constraints":"0 &lt;= Number of Nodes &lt;= 10^5\r\n-1000 &lt;= value of Node data &lt;= 1000\r\n","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n public static Scanner scn = new Scanner(System.in);\r\n\r\n public static class TreeNode {\r\n int val = 0;\r\n TreeNode left = null;\r\n TreeNode right = null;\r\n\r\n TreeNode(int val) {\r\n this.val = val;\r\n }\r\n }\r\n\r\n public static ArrayList<Integer> diagonalOrderSum(TreeNode root) {\r\n\r\n return null;\r\n }\r\n\r\n // input_section=================================================\r\n\r\n public static TreeNode createTree(int[] arr, int[] IDX) {\r\n if (IDX > arr.length || arr[IDX] == -1) {\r\n IDX++;\r\n return null;\r\n }\r\n TreeNode node = new TreeNode(arr[IDX++]);\r\n node.left = createTree(arr, IDX);\r\n node.right = createTree(arr, IDX);\r\n\r\n return node;\r\n }\r\n\r\n public static void solve() {\r\n int n = scn.nextInt();\r\n int[] arr = new int[n];\r\n for (int i = 0; i < n; i++)\r\n arr[i] = scn.nextInt();\r\n\r\n int[] IDX = new int;\r\n TreeNode root = createTree(arr, IDX);\r\n\r\n ArrayList<Integer> ans = diagonalOrderSum(root);\r\n for (Integer j : ans)\r\n System.out.print(j + \" \");\r\n\r\n }\r\n\r\n public static void main(String[] args) {\r\n solve();\r\n }\r\n}\r\n\r\n"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"15\r\n4\r\n2\r\n1\r\n-1\r\n-1\r\n3\r\n-1\r\n-1\r\n6\r\n5\r\n-1\r\n-1\r\n7\r\n-1\r\n-1","sampleOutput":"17 10 1 ","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"2e9df04c-be14-441c-9a18-8b5a8ca6596d","name":"Trees For Intermediate","slug":"trees-for-intermediate-9994","type":0},{"id":"6e2a3a42-ff94-4557-8e9e-e5cc43a486f0","name":"Diagonal Order Sum Of A Binary Tree","slug":"diagonal-order-sum-of-a-binary-tree","type":1}],"next":{"id":"197416b7-d7a7-4cc4-b324-a0f9e191f855","name":"Diagonal Order Sum of a Binary Tree","type":3,"slug":"diagonal-order-sum-of-a-binary-tree"},"prev":{"id":"067e090f-11c7-4c1d-878d-478de44ff67e","name":"Vertical Order Sum of a Binary Tree","type":3,"slug":"vertical-order-sum-of-a-binary-tree"}}}` Editor

# Diagonal Order Sum Of A Binary Tree

medium

1. Given a Binary Tree, print Diagonal order sum of it. 2. For more Information watch given video link below.

## Constraints

0 <= Number of Nodes <= 10^5 -1000 <= value of Node data <= 1000

## Format

### Input

Input is managed for you.

### Output

Output is managed for you.

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}15 4 2 1 -1 -1 3 -1 -1 6 5 -1 -1 7 -1 -1```

### Sample Output

`.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}17 10 1 `

Discussions

Show Discussion

Related Resources 