package com.biplav.algorithms; public class FlattenBST { public static class TreeNode { public TreeNode left; public TreeNode right; public int value; public TreeNode(TreeNode left, TreeNode right, int value) { super(); this.left = left; this.right = right; this.value = value; } } public static class ListNode { public ListNode next; public int value; public ListNode(ListNode next, int value) { super(); this.next = next; this.value = value; } } public static ListNode flatten(TreeNode root) { ListNode left = root.left != null ? flatten(root.left) : null; ListNode base = new ListNode(null,root.value); ListNode right = root.right != null ? flatten(root.right) : null; base.next = right != null ? right : null; if(left == null) return base; else { ListNode home = left; while(left.next != null) left = left.next; left.next= base; return home; } } /* * 6 * 3 8 * 2 4 7 10 */ public static void main(String[] args) { TreeNode t3 = new TreeNode(null, null, 2); TreeNode t2 = new TreeNode(null, null, 4); TreeNode t4 = new TreeNode(t3, t2, 3); TreeNode t7 = new TreeNode(null, null, 7); TreeNode t10 = new TreeNode(null, null, 10); TreeNode t8 = new TreeNode(t7, t10, 8); TreeNode t6 = new TreeNode(t4, t8, 6); ListNode root = flatten(t6); while(root != null) { System.out.println(root.value); root = root.next; } } }
India has the world’s third-largest startup ecosystem, a thriving developer base, and a mobile-first population larger than the US and Europe combined. Yet, no GPT-4. No DeepMind. No Amazon-style platform. Why? Innovation Isn’t Accidental—It’s Engineered The Zerodha Daily Brief recently asked why India hasn’t built a global product company like Apple. The key argument: India isn’t building for the world. It’s solving for local constraints, scale, and affordability—but global scale requires deep IP, design, and tech differentiation. It’s not just about software, it’s about systems thinking. More importantly, it answers the question: Why do countries innovate? The answer isn’t just genius or ambition—it’s incentives and ecosystems. The U.S. Defense Department, for example, accounted for nearly 70% of federal R&D funding during the Cold War. China has pumped billions into semiconductors and AI with long-term national alignment. These aren’t short-term bets—they are strategic, delibe...