<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mo Shoaib</title>
    <description>The latest articles on DEV Community by Mo Shoaib (@shoaib0023).</description>
    <link>https://dev.to/shoaib0023</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F624980%2F837f60a5-b7fb-4dab-9383-8d6d6e1ecba1.jpeg</url>
      <title>DEV Community: Mo Shoaib</title>
      <link>https://dev.to/shoaib0023</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shoaib0023"/>
    <language>en</language>
    <item>
      <title>Advanced Interview Questions</title>
      <dc:creator>Mo Shoaib</dc:creator>
      <pubDate>Sat, 27 Nov 2021 18:14:40 +0000</pubDate>
      <link>https://dev.to/shoaib0023/advanced-interview-questions-m8l</link>
      <guid>https://dev.to/shoaib0023/advanced-interview-questions-m8l</guid>
      <description>&lt;p&gt;Welcome to my post, I will list some of the interview questions that I encountered in the interview process I been through. Hope it will help you to crack your interview process.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Remember, interview process is not about the solution of a problem its all about how you approach the given problem.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Round 1 (Technical Screening):
&lt;/h3&gt;

&lt;p&gt;This round is basically the screening round of around 30-45 mins &amp;amp; its a live coding session in which interviewer can ask questions about your approach for a given problem &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question : Given a tuple &lt;code&gt;[('John', 95), ('Danny', 98), ('Aaron', 90), ('Leo', 94)]&lt;/code&gt; sort this by the name of the person.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One solution can be to use bubble sort on 0th index of each tuple &amp;amp; swapping the whole tuple at a time.&lt;/p&gt;

&lt;p&gt;Another solution can be to use sorted inbuilt method to sort the list of tuples like this -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;people = [('John', 95), ('Danny', 98), ('Aaron', 90), ('Leo', 94)]
# argument to lambda function is the whole list of tuple &amp;amp; it will
# set the key to sort on the basis of the 0th index of each tuple
people = sorted(people, key=lambda x: x[0])
print(people)

Output:
[('Aaron', 90), ('Danny', 98), ('John', 95), ('Leo', 94)]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Question 2: Given a Roman Numeral, convert it to its integer value. for example III -&amp;gt; 3, IV -&amp;gt; 4 and so on.&lt;/strong&gt;&lt;br&gt;
For complete problem statement refer to this &lt;a href="https://leetcode.com/problems/roman-to-integer/"&gt;link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are multiple ways to solve this problem, please give it 10-15 mins &amp;amp; try to breakdown the problem. You can find the solution either at &lt;a href="https://leetcode.com/problems/roman-to-integer/"&gt;leetcode&lt;/a&gt; or at &lt;a href="https://www.geeksforgeeks.org/converting-roman-numerals-decimal-lying-1-3999/"&gt;geeksforgeeks&lt;/a&gt; portal. &lt;/p&gt;
&lt;h3&gt;
  
  
  Round 2 (Technical Round):
&lt;/h3&gt;

&lt;p&gt;In this round, interviewer can ask the Data structures &amp;amp; algorithms along with the technical questions related to the language you are about to work on in that company. So mine was a Python so I can provide you the questions related to python only.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question : What are Enumerations ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Enumerations are created using class, they just have names and values associated with them. In python, you can implement Enumerations using &lt;strong&gt;enum&lt;/strong&gt; module. Enums are iterable, supports hashing &amp;amp; can be accessed either by name or value.&lt;/p&gt;

&lt;p&gt;Example :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import enum

class Programming(enum.Enum):
    python = 1
    java   = 2

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Question : Can be the complexity of fetching an element from a dictionary different than O(1)? In what cases? Is O(1) the best case, worst case, or average-case complexity?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Yes, the complexity of fetching an element from a dictionary can be different than O(1). In worst case scenario, the complexity of getting an element from dictionary is O(N). O(1) is the average case complexity &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question : What are generators? Give a use case?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A generator-function is defined like a normal function, but whenever it needs to generate a value, it does so with the yield keyword rather than return. If the body of a def contains yield, the function automatically becomes a generator function, example :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# A generator function that yields 1 for first time,
# 2 second time and 3 third time
def simpleGeneratorFun():
    yield 1            
    yield 2            
    yield 3            

# Driver code to check above generator function
for value in simpleGeneratorFun(): 
    print(value)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Generators are often used for streaming large amount of data which is obviously memory efficient.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question : What are transactions? If there is a system failure inside the transaction then what will happen?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A transaction is an atomic set of database queries. A transaction in a database system must maintain Atomicity, Consistency, Isolation, and Durability − commonly known as ACID properties − in order to ensure accuracy, completeness, and data integrity.&lt;/p&gt;

&lt;p&gt;The checkpoint is used to declare a point before which the DBMS was in the consistent state, and all transactions were committed.&lt;br&gt;
If there is a system failure inside the transaction then the transaction will rollback to its previous checkpoint.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question : Difference b/w tuple and list, what do you mean by immutable ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The key difference between a tuple and list is that while the tuples are immutable objects the lists are mutable. This means the tuple cannot be changed while the lists can be modified.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question : What is the n+1 problem and how can you solve it ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The N+1 query problem happens when your code executes N additional query statements to fetch the same data that could have been retrieved when executing the primary query.&lt;/p&gt;

&lt;p&gt;Refer to this &lt;a href="https://medium.com/doctolib/understanding-and-fixing-n-1-query-30623109fe89"&gt;link&lt;/a&gt; for in depth details.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question : When should we use MongoDB and when relational database?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It always depends on the use case but generally it's better to use relational databases when the requirements are clear and there are no dynamic attributes involved in the structure. If there some dynamic attributes involved that you are not aware of at the time then its better to use MongoDB or non-relational databases.&lt;/p&gt;

&lt;p&gt;For example, if your designing a database to store the product and their details then maintaining a relational database for the same is much more complex then maintaining a non relational database for the same.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question: What is a gunicorn? How can we scale an application using a gunicorn?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Gunicorn is a WSGI server that takes care of everything which happens in-between the web server and your web application. It also takes care of running multiple instances of your web application, making sure they are healthy and restart them as needed, distributing incoming requests across those instances and communicate with the web server.&lt;/p&gt;

&lt;p&gt;Gunicorn allows us to run multiple worker processes of a single app. It’s really simple, and we can easily scale up or down our number of workers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question&lt;/strong&gt; : How do will you define abstract classes in Python program?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Answer&lt;/strong&gt; : The ABC class is inherited from the abc module to define the abstract class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from abc import ABC

class AbstractLanguage(ABC):
    @abstractmethod
    def created_by(self):
        pass
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To implement this class just inherit it and implement the abstract methods.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Python(AbstractLanguage):
    def created_by(self):
        print("Guido van Rossum")

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Try to design more complex patterns using abstract classes. It will improve your code structure &amp;amp; will make you a better developer than others.&lt;/p&gt;




&lt;p&gt;That's it. Good luck for your next interview, Hope it helps you to gain some knowledge, if you like this article or if you want to add any question/topic here please let me know in the comments. Thanks.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>startup</category>
      <category>challenge</category>
      <category>python</category>
    </item>
    <item>
      <title>Part 1: Basics of Hashing</title>
      <dc:creator>Mo Shoaib</dc:creator>
      <pubDate>Mon, 03 May 2021 19:50:15 +0000</pubDate>
      <link>https://dev.to/shoaib0023/part-1-basics-of-hashing-2fib</link>
      <guid>https://dev.to/shoaib0023/part-1-basics-of-hashing-2fib</guid>
      <description>&lt;p&gt;Hashing is the process of converting a given key into another value. A hash function is used to generate the new value according to the mathematical function. The result of the hash function is known as the hash value. Let's understand this with the help of an example - &lt;/p&gt;

&lt;p&gt;You have been provided a set S of numbers. You have to perform 3 kinds of&lt;br&gt;&lt;br&gt;
queries :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Check if element X is present in the set.&lt;/li&gt;
&lt;li&gt;Add a new element X to this set, if not present&lt;/li&gt;
&lt;li&gt;Delete an element X from this set, if present&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Constraints :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Each element of the set is distinct&lt;/li&gt;
&lt;li&gt;0 &amp;lt;= X &amp;lt;= 10 power 5&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Come on, think about the way how you will solve this problem?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution 1: Naive Approach&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This approach is generally the first hit of our mind. Here, we will loop over the set (you can assume the set as an array) and can easily check the element, add the element and delete an element.&lt;/p&gt;

&lt;p&gt;The complexity of the queries -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    O(N) [Linear Search]
    O(N) [Loop over all the elements in the worst case, add after the last element]
    O(N) [Create a new array excluding that element]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Solution 2: Direct addressing Scheme&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Create a boolean array of the size of the constraint. Initialize all the elements as False. Take the set of given numbers and change to True the corresponding elements in the array.&lt;/p&gt;

&lt;p&gt;Let's say the given set is S = [0, 3, 8, 10, 12]&lt;/p&gt;

&lt;p&gt;A = [T, F, F, T, F, F, F, F, T, F, T, F, T, ................. , F]  &amp;lt;-- dummy boolean array &lt;/p&gt;

&lt;p&gt;The complexity of the queries -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    O(1) [check the value of Xth index of the array, if True then present else not present]
    O(1) [change the value of Xth index to True]
    O(1) [change the value of Xth index to False]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The catch here is that the initialization of this boolean array is O(N) where N is the set's length as we have to loop over the set and populate the boolean dummy array also called the Addressing table. After initialization, all required queries will take O(1) right?&lt;/p&gt;

&lt;p&gt;Downsides of this approach - &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Memory Limitation: In some cases, constraints can be too large to store &lt;/li&gt;
&lt;li&gt;Wastage of memory: If our set S has 5 elements, we still have to initialize an array of size of the constraint&lt;/li&gt;
&lt;li&gt;Limited to only positive integers: Can be used for negative integers with little modification. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Solution 3: Hashing&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;The difference between direct addressing and hashing is instead of directly putting an element in the addressing table we will now pass the element first from the hash function (f(x)) then will store the output of that function in the addressing table.&lt;/p&gt;

&lt;p&gt;ex. f(x) = x % 11 where x is the element of set S&lt;/p&gt;

&lt;p&gt;Now whatever the input is the output of this hash function will be in [0,10]. So, our boolean dummy array will be of length 11&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;A = [F, F, F, F, F, F, F, F, F, F, F, F]
Let's take S = {1, 2, 14, 20, 99} and hash function f(x) = x % 11

Calculate the value of hash function for every element of S - 
-  f(1) = 1 % 11 = 1
-  f(2) = 2 % 11 = 2
-  f(14) = 14 % 11 = 3
-  f(20) = 20 % 11 = 9
-  f(99) = 99 % 11 = 0

Now, we know in A only index 1, 2, 3, 9, 0 will be True

So, A = [T, T, T, T, F, F, F, F, F, T, F]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All three downsides are direct addressing approach is resolved here. &lt;strong&gt;The only catch here is to get the hash function right&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Note: The hash function f(x) = x % 11 is just an example taken for you guys to understand. It's not a good hash function as you can see the collision rate is too high. ex: for x = 3 and x = 25 this hash function will return the same output&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hashing&lt;/strong&gt; - A hash function should follow the mathematical definition of functions (either one to one or many to one) and should be consistent with respect to their outputs. A good hash function distributes the keys as uniformly as possible&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Collision&lt;/strong&gt; - It happens when two or more different inputs to the hash function return the same output. Let's take a hash function,  f(x) = x % 11&lt;/p&gt;

&lt;p&gt;For x = 3 and x = 25 the value of f(x) is same i.e 3. This is known as a collision or a hit.&lt;br&gt;
Less number of hits corresponds to a good hash function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Collision Resolution&lt;/strong&gt; - To resolve or reduced collision certain methods are used. Two well known used algorithms are &lt;strong&gt;Chaining&lt;/strong&gt; and &lt;strong&gt;Double Hashing Technique&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is just the prerequisite to get started on the real problems of hashing. In the next part, we will understand the String Hashing, performance load factor, and other sub-concepts that will give you a solid understanding of hashing and its real-world use case.&lt;/p&gt;

&lt;p&gt;Hope you like this knowledge, please like or comment, cheers. Thanks&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>programming</category>
      <category>productivity</category>
      <category>functional</category>
    </item>
  </channel>
</rss>
