Skip to content

Instantly share code, notes, and snippets.

@pradhuman7d1
pradhuman7d1 / FAQ
Created November 26, 2021 11:08
Kotlin Functions
Q. What is Unit return type?
A. Unit return type is used when we have nothing to return from a function.
Q. Is it possible to return multiple values from a function?
A. Yes, it can be done using Pair or Triple, Pair returns two values and Triple returns three values.
Q. What to do if we need multiple parameters in a funtion but are not sure of the exact number?
A. In such a case, we can use varargs that allows us to pass any number of parameters.
Q. What type of function is this fun add(num1: Int, num2: Int) : Int = num1 + num2?
@pradhuman7d1
pradhuman7d1 / FAQ
Created November 26, 2021 10:12
Kotlin Loops
Q. Why we use loops?
A. Loops are used when we need to do a task repeatedly till a condition satisfies.
Q. What is the use of continue?
A. Whenever we encounter a continue in a loop, all the lines of code below it are skipped and then it jumps back to the top.
Q. What is the use of break?
A. break is used to terminate a loop if a certain condition is encountered.
Q. What is the difference between while and do while loop?
@pradhuman7d1
pradhuman7d1 / FAQ
Last active November 26, 2021 08:24
Kotlin Conditionals
Q. What is when?
A. When works as switch cases.
Q. What is the use of conditional operators?
A. These are used to check some conditions and if they satisfy then only our code block will work.
Q. Can we use a range in when for comparision?
A. Yes, we can use range by using the in keyword.
Q. What if no condition of when is satisfied?
@pradhuman7d1
pradhuman7d1 / FAQ
Created November 26, 2021 07:20
Kotlin Arrays
Q. What should be the datatype of elements stored in an array?
A. In Kotlin you can store multiple datatypes into an array, so it can be any type of element.
Q. How to find if an item is present in an array or not?
A. We can use the contains function to check if an item is present or not. It return true/false.
Q. What is the output of indexOf function?
A. indexOf function as defined by the name returns the index of the element that the user search for and return -1 if element is not present in array.
Q. Can we construct an array that can auto assign values of elements corrosponding to its index?
@pradhuman7d1
pradhuman7d1 / FAQ
Created November 26, 2021 06:11
Kotlin Strings and Ranges
Q. What is equals operator?
A. equals operator is used to check if two strings are equal.
Q. What is the use of string interpolation?
A. String interpolation is used to include variables into a string.
Q. What is compareTo operator?
A. It compares two strings on the basis of its ascii value and provides the output according to the difference of ascii values.
Q. What is a range?
@pradhuman7d1
pradhuman7d1 / FAQ
Created November 26, 2021 05:00
Kotlin Introduction
Q. What are mutable and immutable variables?
A. Mutable variables are the ones that can be modified and reassigned, but immutable variables can't be edited after one assignment.
Q. What is the difference between val and var?
A. var keyword is for creating mutable variables and val is for creating immutable variables.
Q. What is explicit type declaration?
A. Defining the type of a variable while declaration is explicit type declaration. eg: var a : Int = 10
Q. What is type casting?
@pradhuman7d1
pradhuman7d1 / faq
Created November 1, 2021 11:43
virtualos_go
1) Can we add any more functionalities in our OS ?
ans) Definitely, and I'll appreciate your efforts if you do so, you can try to
tweak this and add simple stuffs like, changing the background image on press of a button.
2) How can i integrate a new App into the existing os ?
ans) Simply, copy your app source file into the main project directory and modify its main fuction with a name and
create another button in the main source file of the project and in its callback, simply call you apps function.
3) Why we make variables global here ?
ans) we make our necessary variables global here because we need to intigrate multiple files together and
@pradhuman7d1
pradhuman7d1 / faq
Created October 27, 2021 05:22
Any base multiplication
1) Which base is the most common and used everywhere?
Answer) Base (10) i.e. the decimal number system.
2) Why are we multiplying our single digit product with power before adding it to answer ?
Answer) We need to multiply it with power, because if you can recall, when we used to product two numbers manually, then after
each single digit product when we changed the line, we used to add a trailing 0 to the next single digit product, that's why we use this power.
3) How to decide what the carry should be ?
Answer) The carry depends upon the base of the numbers that we are working on, so let's say if we are working on base 8,
then the carry will be calculated by this formula : carry = num / 8, and the number to keep will be num % 8.
@pradhuman7d1
pradhuman7d1 / faq
Created October 26, 2021 13:32
get maze paths
1) Why we return a new arraylist/ list/ vector when we hit a wrong position ?
Answer) We return a new arraylist/ list/ vector so that means that it is empty, then in that case,
we would not be able to traverse it and add any element to it, so it will prevent any wrong paths to be added as answer.
_________________________________________________________________
2) Why we add an empty string before returning the new arraylist/ list/ vector when we reach the destination ?
Answer) Because when we reach our destination, we need to add that path as our answer, that's why we add an empty string
so our list/ arraylist/ vector does not stay empty and we can traverse it.
_________________________________________________________________
@pradhuman7d1
pradhuman7d1 / faq
Created October 26, 2021 12:08
The state of Wakanda - 1
1) Why we are travelling through the columns in outer loop ?
Answer) We are travelling throught the columns first because if we analyse the problem, then it is clear that the columns are increasing countinuously, while rows are alternating.
_________________________________________________________________
2) Why we are checking if column is odd or even ?
Answer) We are doing so because, after analysing the pattern, we can figure this relation that for every even value of column, we are going downwards through rows and vice versa.
_________________________________________________________________
3) Can we do this with recursion ?
Answer) Yes, it can be done as follows :