Move Zeros to End of Array


 You are given a array of Integers with some 0 in it. Move Zeros to End of Array. You also need to preserve order of non zero values. I/P : 1 0 4 0 7 8 0 Move Zeros to End of Array O/P : 1 4 7 8 0 0 0 Approach This can… Read More »

XOR Between Strings


 You are given two string A and B. B is generated after shuffling A plus one extra character placed at random location in B. Find Out that extra Character. A = ” abcde ” B = ” abbdec ” Output : b Approach : We will use XOR to find out extra character. As every… Read More »

Reverse Vowels of a String


 You are given a string, you just need to reverse vowels in the string. I/P : hello O/p : holle I/p : coder O/p : cedor Approach : Take 2 variable i = 0 , j = string size -1 Now, Compare characters at i and j position, we have 4 cases. 1. s [… Read More »

Connected Components In a UnDirected Graph


 Connected Components In a UnDirected Graph   Finding Number of Connected Components can be done using any graph traversal algorithm. Such as Depth First Searchor Breadth First Search. Pseudo Code : For all the vertex : If vertex ‘i’ is not visited DFS ( i ) Increment Count //count : Number of time you have… Read More »

Find if Given String is Sub sequence of Other String


 You are Given Two strings S and T. Find if Given String is Sub sequence of Other String. S = ” bacd ” T = ” binarycoder ” S is a Sub sequence of T. Approach : Straight Forward Linear Approach. Traverse Both Strings from 0 till any one of the string finished. IF S[… Read More »

Mid of the Linked List In One Traversal


 Find mid of the linked list in one traversal of the linked list.   Algorithm 1 1) Traverse linked list and count total number of nodes. 2) Traverse again till count/2. Total Number of times we need to traverse linked list n + n/2 = 3n/2 Algorithm 2 1) We will take two pointers both… Read More »

Print Substring of a String in C


  Substring of a String SubString A substring is a string which is a part of some other string. For example: “coder” is a substring of “binarycoder”. For more Info:wiki   C  Implementation :   OUTPUT a ab abc b bc c