Category: fullstackdevelopment

  • Valid Sudoku

    Given a board of size 9 * 9 representing a sudoku game , find out if it is valid. It is valid if : For example, The below sudoku: represented by the array: Input: board = [[“5″,”3″,”.”,”.”,”7″,”.”,”.”,”.”,”.”] ,[“6″,”.”,”.”,”1″,”9″,”5″,”.”,”.”,”.”] ,[“.”,”9″,”8″,”.”,”.”,”.”,”.”,”6″,”.”] ,[“8″,”.”,”.”,”.”,”6″,”.”,”.”,”.”,”3″] ,[“4″,”.”,”.”,”8″,”.”,”3″,”.”,”.”,”1″] ,[“7″,”.”,”.”,”.”,”2″,”.”,”.”,”.”,”6″] ,[“.”,”6″,”.”,”.”,”.”,”.”,”2″,”8″,”.”] ,[“.”,”.”,”.”,”4″,”1″,”9″,”.”,”.”,”5″] ,[“.”,”.”,”.”,”.”,”8″,”.”,”.”,”7″,”9″]] is valid since it obeys all the three conditions. Try…

  • Merge Sorted Array

    Given two sorted arrays and their sizes , merge the two into the first sorted array. Extra space equal to the size of the second array is provided at the end of the first array. For example, Given the arrays: num1 = [1,2,3,0,0,0] , size = 3 ( remaining space for the second array to…

  • Inorder traversal of a Tree

    Given the root node of a Tree , return the node values in a list in inorder. For example, For the below tree: The inorder traversal is [ 0,2,3,4,5,6,7,8,9] Try out the solution here: https://leetcode.com/problems/binary-tree-inorder-traversal Solution: There are three ways to do inorder traversal: Let’s look into each of them. Approach 1 – Recursion: In…

  • Convert Roman to Integer

    Given a string representing a roman numeral , convert it into an integer. The values of each roman character is also given: Symbol Value I 1 V 5 X 10 L 50 C 100 D 500 M 1000 For example, IV means 4 XX means 20 Try out the solution here: https://leetcode.com/problems/roman-to-integer/ Solution: Have a…

  • Add two numbers represented by Linked List

    Given two numbers represented by a linked list in reverse order. You have two linked lists. Each of them represent a number which is not empty and not negative. Each of the node in the linked lists represent a single digit. The numbers are linked in reverse order. Create a linked list with their sum…

  • How to implement Trie Data Structure?

    Trie is a datastructure useful to store set of words. It is a tree with a lot of children , one for each letter of the alphabets. So if you want to store lower case English letter words each node can have unto 26 child nodes. Every word is represented by as many nodes as…

  • Construct Binary Tree From Preorder and Inorder Traversals

    Given the preorder and inorder traversal arrays of a tree, construct it. For example, Given preorder = [3,9,20,15,7], inorder = [9,3,15,20,7] You need to construct the below tree: you need to return the root node of the above tree in your code. Try it here: https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/ Solution: Hint: Using root node from preorder traversal ,…

  • Level Order Traversal of a Binary Tree

    Given the root of a binary tree , return the level order traversal of the binary tree . Level order traversal means picking nodes from left to right level by level. For example, For the below tree: Level order traversal is [[3],[9,20],[15,7]] It is a list of lists. Each list represent the nodes at that…

  • Maximum Path Sum in a Binary Tree

    Given a binary tree, find the maximum path sum . A path is a sequence of nodes connected by edges. You can start from any node and go to any node in the tree as long as they are connected by edges. Also the same node cannot be present more than one in the sequence.…

  • Data Structures & Algorithms in Java – Graphs – Alien Dictionary.

    Problem: You are given a list of English words arranged lexically (as in a dictionary). But not in the order of English alphabets but in the order of an alien language which uses English script. With the given words you need to arrange the letters in the right order of the alien dictionary. For example,…