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.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 / 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
@rozer007
rozer007 / Mcq.txt
Created November 23, 2021 12:10
STRING , STRINGBUILDER AND ITS FUNCTION IN C#
Q1) What will be the output of this code?
string str="hello pepcoder";
Console.WriteLine(str.Substring(0,8));
a) hello pe
b) hello pep
c) ello pe
d) ello pep
ans: b)
@rozer007
rozer007 / faq.txt
Created November 24, 2021 04:43
List and exception handling in c#
Q1) How to create a 2d array in list?
ans: List<List< data_type>> 2dlist = new List<List< data_type>>();
2dlist.Add(new List<data_type>())
Q2) How can we raise an exception in c#?
ans: We can raise an exception manually in c# using the throw keyword.
Q3) How to get the number of element in a nth dimension of a List?
ans: We can get the number of element by this statement list[n-1].Count;
@rozer007
rozer007 / Faq.txt
Last active November 24, 2021 04:43
Array in C#
Q1) Difference between List and array?
ans Array are static with a fixed size whereas List are dynamic and size can be change according to our need.
Q2) What does split function do?
ans: It convert a string into a array by spliting the string by a character and each word is stores as an element in an array.
Q3) How can we add at the front of a list?
ans: We can use the Insert function to add at index 0.
eg. list.Insert(0,element you want to add).