Skip to content

Instantly share code, notes, and snippets.

@rozer007
rozer007 / Hints
Created October 26, 2021 11:40
Kth Node From End Of Linked List
Hint 1: Try to use two pointer or find the size of the array and find the kth node
Hint 2: keep two pointers and update one with k steps ahead.
Hint 3: The kth node is the node where pointer with delay a of k steps is pointing.
@rozer007
rozer007 / Faq
Created October 26, 2021 12:34
Print Decreasing
Q1) What is the time complexity?
ans: As n calls are made and work is done corresponding to these n calls therefore the time complexity becomes O(n).
Q2) What is the space complexity?
ans: Since no extra space is used, therefore space complexity is constant, however you should know that if the recursion call stack is taken into account, then space complexity will be O(n) as there are n recursive calls.
Q3) What is base condition?
ans: Since we are printing in decreasing order we are going to stop our recursive call when the n is 0.
@rozer007
rozer007 / Faq
Created October 27, 2021 07:26
The Curious Case Of Benjamin Bulbs
Q1) Why only perfect square are on after the nth number of fluctuation ?
ans: All perfect square numbers have odd numbers of factors so it will be on after nth number of fluctuation.
Q2) Why is the condition i*i<=n ?
ans: Since we are checking only the perfect square that why we are checking the condition for square.
Q3) what will the time complexity and space complexity ?
ans: time complexity : O(logn)
Space complexity : O(1)
@rozer007
rozer007 / Faq
Created November 19, 2021 04:11
Strings and its method
Q1) What are Strings in ruby?
ans: Just like all other language , even in ruby string are the collection or group of character.
Q2) Are String mutable in ruby?
ans: Yes , string are mutable in ruby.
Q3) What is the function to find the size of the string?
ans: String_name.size()
Q4) How to convert string to integer ?
@rozer007
rozer007 / Faq
Last active November 25, 2021 07:53
Arrays in ruby
Q1) How can we find if a elements is present in an array or not ?
ans: array_name.include?(element)
Q2) How to add a element at the starting of the array?
ans: array_name.unshift(element)
Q3) Initialize the array with a particular elements while creating an array?
ans: array_name=Array.new(size,initial value)
Q4) How to find the permutation of an array ?
@rozer007
rozer007 / Faq.txt
Last active November 25, 2021 07:55
Hashes in Ruby
Q1) Difference between update function and merge function ?
ans: Update combine 2 hashes in a destructive way with update or with no overwriting whereas merge function will just merge the two hash without overwritting
Q2) Can we convert hash from any array?
ans: No we can't ,for an array to convert to hash ,the number of elements in the array should be even.
Q3) How to access both key and value
ans: hash_name.each do|key,value|
end
@rozer007
rozer007 / Faq.txt
Created November 19, 2021 06:33
File IO
Q1) What is difference between a and a+ mode?
ans: a - Append to a file.The file is created if it does not exist.
a+ - Open a file for reading and appending. The file is created if it does not exist.
Q2) Is it mandatory to close the file after opening.
ans: Yes ,if we didn't close then it will leak file descriptors.
Q3) When we use File.open() ,what type of object is created?
ans: File object ,it can be check using .class function.
@rozer007
rozer007 / Faq.txt
Created November 19, 2021 07:02
Enumerable in Ruby
Q1) What are enumerable in ruby?
ans:It is module which give the class the capabilities to use collection method.
Q2) What function is necessary to include in class to include enumerable?
ans: def each function is required to present in the class.
Q3) What is the function to check whether a value is present in the enumerable or not?
ans: We use find() function.
Q4) What are the which have pre defined Enumerable module.
@rozer007
rozer007 / Faq.txt
Last active November 25, 2021 07:50
polymorphism and symbols in ruby
Q1) How to declare a symbol in ruby?
ans: Before the symbol name we need use ":" character to define a symbol.
Q2) How many type of polymorphism can be done in ruby?
ans: Two types : i) using inheritance
ii) using duck typing
Q3) What is duck typing in polymorphism ?
@rozer007
rozer007 / Mcq.txt
Created November 23, 2021 08:29
Introduction to C#
Q1. How to take a input in c# :
a) Console.writline()
b) Console.Readline()
c) Console.Readall()
d) Console.ReadLine()
ans: d) Console.ReadLine()
Q2) Which of the following are not datatypes of c# :
a) int