We are given the range having start and end numbers and the task is to calculate the total count of Fibonacci numbers available between the given range in O(Log n) time and O(1) space.What are Fibonacci numbersFibonacci numbers are the sequence of numbers known as Fibonacci sequence where every new number is the sum of the last two preceding numbers.Where, f(0) = 0 and f(1) = 1 i.e. f(0) and f(1) have fixed positions in the sequence and the calculation will start from the third number.Formula used for calculating the sequence is −Fn = Fn-1 + Fn-2Where, F0 = 0, ... Read More
To count by multiple fields, use $facet in MongoDB. The $facet processes multiple aggregation pipelines within a single stage on the same set of input documents. Let us create a collection with documents −> db.demo721.insertOne( ... { ... ... "details1": { ... "id":101 ... ... }, ... "details2": { ... "id":101 ... }, ... "details3": { ... "id":101 ... } ... } ... ); { "acknowledged" : ... Read More
To update all the values, use update() along with multi:true. Let us create a collection with documents −> db.demo720.insertOne({"SubjectName":"MySQL"}); { "acknowledged" : true, "insertedId" : ObjectId("5eaae7ca43417811278f5883") } > db.demo720.insertOne({"SubjectName":"Java"}); { "acknowledged" : true, "insertedId" : ObjectId("5eaae7ce43417811278f5884") } > db.demo720.insertOne({"SubjectName":"C"}); { "acknowledged" : true, "insertedId" : ObjectId("5eaae7d143417811278f5885") } > db.demo720.insertOne({"SubjectName":"C++"}); { "acknowledged" : true, "insertedId" : ObjectId("5eaae7d543417811278f5886") }Display all documents from a collection with the help of find() method −> db.demo720.find();This will produce the following output −{ "_id" : ObjectId("5eaae7ca43417811278f5883"), "SubjectName" : "MySQL" } { "_id" : ObjectId("5eaae7ce43417811278f5884"), "SubjectName" : "Java" } { ... Read More
To add a new field, use the $addFields in MongoDB. Let us create a collection with documents −> db.demo719.insertOne( ... { ... "Number":"7374644", ... "details" : { ... "otherDetails" : [ ... { ... "ProductId" :"102", ... "ProductPrice" : NumberInt(500) ... }, ... { ... "ProductId" :"103", ... ... Read More
We are given an integer value and the task is to first calculate the factorial of a number and then calculate the total number of digits in a result.What is a factorial numberFactorial of a number is calculated by multiplying the digits in a number while decrementing the value of digit by 1. It is denoted by the symbol ‘!’ i.e. 0!, 1!, 2!, 3!, 5!, ...., etc. Factorial of 0! and 1! is always 1.I.e. factorial of 2 = 2 * (2-1) = 2 * 1 = 2 factorial of 3 = 3 * (3-1) * ... Read More
We are given the range starting from an integer value holded by a variable let’s say start till the variable end and the task is to count the total number of factorial numbers available in the given range.What is a factorial numberFactorial of a number is calculated by multiplying the digits in a number while decrementing thevalue of digit by 1. It is denoted by the symbol ‘!’ i.e. 0!, 1!, 2!, 3!, 5!, ...., etc. Factorial of 0! and 1! is always 1.I.e. factorial of 2 = 2 * (2-1) = 2 * 1 = 2 ... Read More
We are given with an integer number and the task is to count the even numbers and the odd numbers in a digit. Also, we will keep check on whether the even digits in an integer are occurring an even number of times and also the odd digits in an integer are occurring an odd number of times.For ExampleInput − digit = 12345 Output − count for even digits = 2 count for odd digits = 3Explanation − Yes, Also, even digits are occurring even number of times i.e. 2 and odd digits are occurring odd number ... Read More
We are given with the two strings let’s say str1 and str2 and the task is to find the count of common characters in two strings i.e. if str1[i] = str[j], then they will be considered as a pair and count will increased to 1 and if str1[i]!=str2[j] then they willn’t be considered as a pair and count willn’t increase to 1.For ExampleInput − str1 = “hello” str2 = “heoo” Output − count is: 3Explanation − str1[0] = str2[0] i.e. h ; str1[1] = str2[1] i.e. e ; str1[2]!=str2[2] i.e. l and o; str1[3]=str2[3] i.e. o. So, the ... Read More
We are given a string of any length and the task is to convert the string having uppercase letters to lowercase letters and lowercase letters to uppercase letters.For ExampleInput − string str = ”Welcome To The Site!”Output − wELCOME tO tHE sITE!Explanation − converted the letters W, T, T, S to lowercase and letters e, l, c, o, m, e, o, , i, t, e to uppercase and it doesn’t perform any operations to the special characters.Input − string str = ”HELLO”Output − helloExplanation − converted the letters H, E, L, L, E to lowercase.This can be done using two different approachesUsing inbuilt functions provided by ... Read More
The task is to convert the distance from kilometers to meters and centimeters in PL/SQL.PL/SQL is the extension of SQL which combines the Data manipulation of SQL with the working of procedural language.According to the problem we should have distance in kilometers whose value we have to convert in meters and centimeters.As per the conversion rule −1km = 1000 meters1km = 100000 centimetersAccording to this conversion rule we want the distance to be converted by a logic in PL/SQL.ExampleInput: kilometer = 10 Output: meter = 10000 Centimeter = 1000000 Input: kilometer = 9 Output: meter = 9000 Centimeter ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP