## Negate a number using addition operator

Problem: Given a number X, flip it to -X. Time complexity : O ( X ) Logic : The negation can be implemented by adding -1, X times. Solution :

Skip to content
# Category: Fundamentals

##
Negate a number using addition operator

##
Implement a power function

##
Withdraw all money from bank account

##
Print half pyramids using * as shown

##
Binary tree traversal

##
Create a binary search tree in javascript

##
Create a simple queue using javascript

##
Check if an element exists in an array, based on that update an array

##
Determine character frequency in the given string

##
Convert the given array of elements to a string

Problem: Given a number X, flip it to -X. Time complexity : O ( X ) Logic : The negation can be implemented by adding -1, X times. Solution :

Naive logic: Loop through the number of times the exponent, and during each iteration multiply the base If our exponent is 10,000 then our loop has to run 10,000 times. But we can optimize...

Problem : You have some money in your bank account, the only function to withdraw money is Withdraw(value), if the value is greater than the money you have it returns 0, otherwise it withdraws...

Pattern 1 : * ** *** **** ***** Logic : i height Number of * (= i) 1 5 1 2 5 2 3 5 3 4 5 4 5 5 5 Solution :...

Problem description : Tree traversal (a.k.a tree search) is a form of graph traversal and refers to the process of visiting each node in a tree data structure, exactly once, in a systematic way....

Create a simple binary search tree data structure in javascript. Binary tree : It is a tree data structure in which each node has at most two children, which are referred to as the...

Problem description : Create a simple queue data structure in javascript. Queue organizes data into the sequential order. It similar to the a queue of people waiting to get a bus ticket. It’s a...

Problem description : Write a function which detects if the given element exists in an array or not. If it does not exist then adds it to an array If it does exist then...

Problem description : Create a character frequency analysis table for the given string. Input : A string // “foo bar” Output : A JSON // {” “: 1, a: 1, b: 1, f: 1,...

Problem description : Write a function that converts a given array into a string. Input : An Array Output : A String Logic : Iterate through array concatenate the new element into the string...