Computer Programming
440 subscribers
6 files
231 links
We mainly post about Tech Interview Prep, Machine Learning, Full Stack, Data Structures, Algorithms & Programming Languages.

Please check the pinned message and invite your friends to this channel. Sharing is Caring đź’•
Download Telegram
Find the largest and the smallest element of a Vector

Problem Statement: Given a vector, find the largest and the smallest value of it. Solution : Example: Input: {1,22,42,5,55,-21,43} Output: Minimum = -21 , Maximum = 55 Input: {88,77,22,44,11,-121,92} Output: Minimum : -121, Maximum : 92 This problem can be solved easily using C++’s Standard Template Library. C++'s STL: The C++ STL (Standard Template Library)…

https://thecodingbot.com/find-the-largest-and-the-smallest-element-of-a-vector/
std::max_element() in C++ STL

std::max_element() is a utility function under header in C++ STL. The purpose of the function is to give the maximum element value of a container(vector, array etc) within a given range [start, end). Now, the question arises, when we have the std::max(), what is the point of the std::max_element() ? The answer is, there…

https://thecodingbot.com/stdmax_element-in-c-stl/
Delete the entire row if any column has NaN

Problem Statement: Given a dataframe, delete all the rows if any column has a NaN value. Solution : The first approach uses Dataframe.dropna() method and the solution is pretty elegant and relatively easy. However, the second solution is not so straightforward, also not recommended as it is SLOW. Approach 1: Using Dataframe.dropna() Dataframe.dropna() provides easy…

https://thecodingbot.com/delete-the-entire-row-if-any-column-has-nan/
Merge two text columns into a single column in a Pandas Dataframe

There are times when you are doing feature engineering for a data science project and you need to form a new feature by combining two text columns. For example, you are given a dataset with people’s information residing in a city. The columns in the dataset are – First Name, Last Name, Salary, Social Security…

https://thecodingbot.com/merge-two-text-columns-into-a-single-column-in-a-pandas-dataframe/
Markdown in Jupyter/Ipython notebook cheatsheet

It makes a huge difference if you present your data science work with clean code, amazing graphs and Markdowns(WoW) !!! We often get so indulge in getting things done that we forget about the representation. Markdowns in Jupyter notebooks beautify them and also improves the readability of the code. Remember to add graphs and plots…

https://thecodingbot.com/markdown-in-jupyter-ipython-notebook-cheatsheet/
Channel photo updated
A Quick Guide on IPython(Jupyter) Magic Commands

In addition to the normal python syntax, Jupyter(Ipython) has some more enhancements. These are known in Jupyter(Ipython) as the magic commands, and starts with a prefix character %. These commands provide various utility operations, makes the common tasks easy. There are two types of magic commands: Line Magic : Denoted by %(single percent sign). These…

https://thecodingbot.com/a-quick-guide-for-ipythonjupyter-magic-cells/
Rearrange a linked list such that all even index nodes come after all odd index nodes

Problem Statement: Given a singly linked list, group all odd nodes together followed by all the even nodes. Please note here we are talking about the node number and not the value in the nodes. The program should run in O(1) space complexity and O(nodes) time complexity. Solution: It’s a classic interview problem and pretty…

https://thecodingbot.com/rearrange-a-linked-list-such-that-all-even-index-nodes-come-after-all-odd-index-nodes/
Print all the ancestors of a node in a Binary Tree

Problem Statement: Given a binary tree print all the ancestors of a node. Example: For the below tree, Ancestors of node 14 are 11,12 and 10. The ancestor of 12 is 10. The ancestors of 11 are 12 and 10. The ancestors of 13 are 12 and 10. The ancestors of 9 are 8 and…

https://thecodingbot.com/print-all-the-ancestors-of-a-node-in-a-binary-tree/
Given a binary tree find the node at the deepest level

Problem Statement: Given a binary tree, find the node at the deepest level. If there are more than one nodes at the last level, return any of them. Solution: This problem can be solved both recursively and iteratively(using level order traversal). It is a classic interview question and often asked in many telephonic and round-1 interviews. Just…

https://thecodingbot.com/given-a-binary-tree-find-the-node-at-the-deepest-level/
Check if two binary trees are a mirror image of each other

Problem Statement: Given two binary trees, find if they are a mirror image of each other. Solution: Example : The below two trees are mirror image to each other. Two trees mirror image of each other Two trees are said to be a mirror image of each other when the following criteria satisfy: Root Node…

https://thecodingbot.com/check-if-two-binary-trees-are-a-mirror-image-of-each-other/
Extract digits from a string in Python

Problem Statement: Given a string, extract all the digits from it. Solution: Imagine a scenario where you have a string of names and salaries of persons in the form, “Adam 200 Mathew 300 Brian 1000 Elon 3333“. From the given string, you need to separate only the salaries of all the person to perform some…

https://thecodingbot.com/extract-digits-from-a-string-in-python/
Python str.isdigit() and its application

Python provides several string methods such as str.capitalize(),str.count(), str.encode(), str.find() etc. One such string method is str.isdigit(). str.isdigit() - Syntax: your_string.isdigit() Parameters: Doesn’t take any. Returns – It returns True if all the characters in the string your_string are digits with a condition that the string should not be empty. If all the conditions are…

https://thecodingbot.com/python-str-isdigit-and-its-application/
Python ord() function and its application

In Python, ord() is a built-in function which returns an integer representing the Unicode point value of a character. Before discussing about ord() method, it is important to know what a Unicode encoding is. Unicode: Unicode is the encoding type or standard which contains the character set of all the languages that exist, all around…

https://thecodingbot.com/python-ord-function-and-its-application/
Python abs() and its applications

Python provides many built-in functions, some falls in the category of essential built-in functions while other falls in Non-essential built-in functions. One such essential built-in function is abs(). In this article, we will talk about abs() and its application. abs(x) : abs(x) is a built-in function which returns the absolute value of a number. Syntax:…

https://thecodingbot.com/python-abs-and-its-applications/
Complex number representation in Python

A complex number is a combination of a real and imaginary number in the form x+iy. Here, x and y are the real numbers, and the i is called the “unit imaginary number” or iota. It is the solution to the equation, . There exist two ways to represent a complex number in mathematics: Rectangular…

https://thecodingbot.com/complex-number-representation-in-python/
std::min_element() in C++ STL

std::min_element() is a utility function under library in C++ STL. The purpose of the function is to give the minimum element value of a container(vector, array etc) within a given range [start, end). Now, the question arises, when we have the std::min(), what is the point of the std::min_element() ? The answer is, there…

https://thecodingbot.com/stdmin_element-in-c-stl/
How to get Unicode code of a character in Python

What is a Unicode encoding? Unicode is the encoding type or standard which contains the character set of all the languages that exist, all around the world. Each character is mapped to an integer known as a Code point. It uniquely identifies a character among the other characters.  The Unicode encoding came into existence when languages other…

https://thecodingbot.com/how-to-get-unicode-code-of-a-character-in-python/
Python’s built-in bin() method with examples

Among many highly useful built-in functions, bin() is also one of them. It was added in Python 2.6, and since then its support has not been deprecated or removed. It is similar to the hex() method which returns the hexadecimal form of the integer while this returns the binary form. bin(x): bin(x) returns the binary…

https://thecodingbot.com/pythons-built-in-bin-method-with-examples/
Convert a binary number(base 2) to the integer(base 10) in Python

Python has hundreds of utility functions that are built-in which ease our efforts to a great extent. Today, the problem we have in hand “Conversion of a binary number to its integer form(base 10)“, python has some built-in methods for this as well. In this article, we will go through different ways we can convert…

https://thecodingbot.com/convert-a-binary-numberbase-2-to-the-integerbase-10-in-python/