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/
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/
The Coding Bot
Find the largest and the smallest element of a Vector - The Coding Bot
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 = 55Input: {88,77,22,44,11,-121,92}Output: Minimum : -121, Maximum : 92 This problem can be solved…
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/
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/
The Coding Bot
std::max_element() in C++ STL - The Coding Bot
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()…
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/
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/
The Coding Bot
Delete the entire row if any column has NaN - The Coding Bot
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…
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/
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/
The Coding Bot
Merge two text columns into a single column in a Pandas Dataframe - The Coding Bot
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…
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/
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/
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/
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/
The Coding Bot
A Quick Guide on IPython(Jupyter) Magic Commands - The Coding Bot
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…
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/
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/
The Coding Bot
Rearrange a linked list such that all even index nodes come after all odd index nodes - The Coding Bot
In this tutorial, we will see diffferent approached to 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/
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/
The Coding Bot
The Coding Bot - Print all the ancestors of a node in a Binary Tree
Given a binary tree print all the ancestors of a node. The ancestor of a node: A node that is connected to all lower-level nodes is called an "ancestor". The connected lower-level nodes are "descendants" of the ancestor node.
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/
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/
The Coding Bot
Given a binary tree find the node at the deepest level - The Coding Bot
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.
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/
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/
The Coding Bot
Check if two binary trees are a mirror image of each other - The Coding Bot
Problem Statement: Given two binary trees, find if they are mirror image of each other. Two trees are said to be mirror image of each other when the following criteria satisfies ...
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/
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/
The Coding Bot
Extract digits from a string in Python - The Coding Bot
Given a string, extract all the digits from it. The following article demonstrate different ways 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 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/
The Coding Bot
Python str.isdigit() and its application - The Coding Bot
Python provides several string methods such as str.capitalize(),str.count(), str.encode(), str.find() etc. One such string method is str.isdigit(). Return true if all characters in the string are digits and there is at least one character, false otherwise.
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/
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/
The Coding Bot
Python ord() function and its application - The Coding Bot
In Python, ord() is a built-in function which returns an integer representing the Unicode point value of a character.
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/
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/
The Coding Bot
Python abs() and its applications - The Coding Bot
Python provides many built-in functions, one such essential built-in function is abs(). In this article, we will talk about abs() and its application.
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/
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/
The Coding Bot
Complex number representation in Python - The Coding Bot
In Python, we can represent the complex number in both the form,rectangular and polar. cmath library provides several utility functions for complex number arithmetic and operations.
