Kamal Rawat's Blog, page 3

January 1, 2020

How to compute the time and space complexity of Binary Tree Algorithms

To learn about computing time and space complexities of Array algorithms, watch the Part-1:

 •  0 comments  •  flag
Share on Twitter
Published on January 01, 2020 20:40

Find minimum cost to travel to the destination railways station

There are N stations on a railway track. You are at the first station and you want to go to the final railway station. You can either go directly or take breaks in between. Given the cost of travel for each pair of stations, find the minimum cost of travel.
 •  0 comments  •  flag
Share on Twitter
Published on January 01, 2020 19:55

December 29, 2019

Tricks to compute the time and space complexities. Part-2 (Binary Tree)

Learn the tips and tricks to find the time and space complexities of Binary tree algorithms:
 •  0 comments  •  flag
Share on Twitter
Published on December 29, 2019 02:08

December 28, 2019

Tricks to compute the time and space complexities. Part-1 (Array)

The following video talks about the general method to find the time and space complexities of your code, esp. during the interview. This is Part-1 of a multi-part series of videos on time complexities.
 •  0 comments  •  flag
Share on Twitter
Published on December 28, 2019 06:52

December 26, 2019

Bitwise Operations: Working on individual bits

Write code to perform the basic operations on individual bits of a number (rather than the entire number): setBit – Set a particular bit. resetBit – Reset a particular bit. toggleBit – Toggle a particular bit. getBit – return the value (0 or 1) stored at a particular bit position.
 •  0 comments  •  flag
Share on Twitter
Published on December 26, 2019 18:04

December 25, 2019

March 13, 2019

Reverse only the alphabets in a string

Given a string that has alphabets and special characters. Write code that reverse only the alphabets in the string and does not change the special characters. INPUT STRING: AB$C^ÞF* OUTPUT: FE$D^ËA* We have discussed a simple code to reverse a string in this post. We use the same logic here, the only difference here is […]
 •  0 comments  •  flag
Share on Twitter
Published on March 13, 2019 11:18

Reverse a string

Write a simple code to reverse a string. INPUT: "HELLO WORLD" OUTPUT: "DLROW OLLEH" The logic to reverse a string is simple, swap the first character with last character, the second character with the second-last character and so on… Take two variables low and high to hold the indices of first and last element, increment […]
 •  0 comments  •  flag
Share on Twitter
Published on March 13, 2019 11:14

October 13, 2018

Maximum consecutive integers present in an array

Given an array of integers. Find the maximum number of consecutive integers present in the array. For example, if the array is: int arr[] = { 2, 24, 22, 60, 56, 23, 25}; Then the answer should be 4, because there are 4 consecutive integers present in the array (22, 23, 24, 25). Solution: The […]
 •  0 comments  •  flag
Share on Twitter
Published on October 13, 2018 23:29

Recursive Bubble Sort

Give the recursive implementation of the Bubble Sort algorithm Solution: We have already discussed the Bubble sort algorithm and its optimizations in this post. The iterative algorithm for bubble sort is shown below: void bubbleSort(int *arr, int n) { for(int i=0; i arr[j+1]) swap(&arr[j], &arr[j+1]); } […]
 •  0 comments  •  flag
Share on Twitter
Published on October 13, 2018 21:40