Skip to content

Instantly share code, notes, and snippets.

View radhar's full-sized avatar

Chakradhar Gembali radhar

View GitHub Profile
@radhar
radhar / sorting.js
Created July 16, 2020 15:21
There is an array of numbers from 1 to 100 which are not in order. Sort the array in O(N) complexity.
There is an array of numbers from 1 to 100 which are not in order. Sort the array in O(N) complexity.
// implemented the function to sort any given array
function sortValues(arrofUnsorted){
var minimum = arrofUnsorted[0];
var maximun = arrofUnsorted[0];
var arrSorted = [];
var temp;
@radhar
radhar / binarytreeheight.java
Created July 16, 2020 15:14
Given a binary tree, find the height of the binary tree.
Given a binary tree, find the height of the binary tree.
Expected: Input: Root node of the tree Output: Height of the tree.
public class BinaryTree {
//Represent the node of binary tree
public static class Node{
int data;
Node left;
@radhar
radhar / rotate.js
Last active July 16, 2020 14:26
Given an array, rotate the array to the right by k steps, where k is non-negative
Given an array, rotate the array to the right by k steps, where k is non-negative.
Expected: Input: [1,2,7,8,9] & k=3 (3 steps) Output: [7,8,9,1,2]
// implemented function to rotate the array in anticlockwise.
function rotateRight(arrRotate, step){
// adding the new elements to the end of the array based on the step value.
for (var i=0; i<step ; i++)
{
arrRotate.push(arrRotate[i]);