Tuesday, April 20, 2021

Printing out all the permutations of string

How to generate permutation of a given string where digits are kept as it is, but alphabets are replaced by lower and upper case characters The above solution uses immutable strings so its not efficient time complexity-wise below solution replaces string with list

Monday, April 19, 2021

Palindrome Linked List

Given the head of a singly linked list, return true if it is a palindrome. 

 Example 1: Input: head = [1,2,2,1] 
Output: true 

Example 2: Input: head = [1,2]
 Output: false 

 Constraints: The number of nodes in the list is in the range [1, 105]. 0 <= Node.val <= 9 
 Follow up: Could you do it in O(n) time and O(1) space?

Saturday, March 27, 2021

Selection sort implementation in python

Here is a simple python implementation of selection sort. The asymptotic complexity of selection sort is n^2

Wednesday, February 19, 2020

Balanced Binary Tree from sorted array

Create a balanced binary tree from sorted array


Array character sequence replacement with another array sequence

In this program a character sequence in an an array is replaced with another.

 Example

 Input string : "mary had a little lamp"

 "little" needs to be replaced with "big"

 Output string : " "mary had a big lamp"