Check If Three Points Are Collinear in C++

Farhan Muhamed
Updated on 17-Jun-2025 19:15:26

3K+ Views

Given coordinates of three points in 2D plane, and the task is to check whether the points are collinear or not. For Example, // Input: Coordinates of three points points = {{2, 3}, {4, 6}, {6, 9}}; // Output The points are collinear. What are Collinear Points? Points are said to be collinear if they lie on the same line and they are not collinear if they are on the different lines. Given below is the figure of collinear and non-collinear points. Checking Collinearity with Area of Triangle To form a triangle, we ... Read More

Four Divisors in C++

Ravi Ranjan
Updated on 17-Jun-2025 17:59:02

612 Views

In this article, we will understand the four divisors problem. We have an array of integers, and our task is to find the sum of divisors of the array elements that have exactly four divisors. If there is no such integer in the array, then return 0. Here is a detailed example given below: Example The following example implements four divisors sum problem: Input: arr = [5, 10, 15, 8] Output: 57 The explanation of the above example is as follows: Divisors of 5 = (1, 5) => count != ... Read More

Break a Palindrome in C++

Ravi Ranjan
Updated on 17-Jun-2025 17:57:32

2K+ Views

In this article, our task is to break a palindromic string. We have to replace exactly one character with any lowercase English letter such that the string becomes a lexicographically smallest possible string that isn't a palindrome. Now after doing so, we have to find the final string. If there is no way to do so, then return the empty string. Example Here is an example of breaking the given palindrome string by replacing one letter and the output is a non-palindromic lexicographically smallest string: Input: abccba Output: aaccba In the above ... Read More

Reverse an Array in Groups of Given Size in Python

Yaswanth Varma
Updated on 17-Jun-2025 17:38:21

637 Views

In Python, Arrays are commonly used to store and manage collections of data. In this article, we are going to learn how to reverse an array in groups of a given size. For example, let's consider the array and a number k, which represents the size of the array. The goal is to break the array into smaller parts, each containing k elements, and then reverse the elements inside each part. If the elements left at the end are less than k, we will reverse them. Suppose the array is [1, 2, 3, 4, 5, 6] and k=3, then ... Read More

Cyclically Rotate an Array by One in Python

Yaswanth Varma
Updated on 17-Jun-2025 17:37:34

2K+ Views

The cyclic rotation of an array involves moving every element of the array one position forward, and the last element gets moved to the first position. For example, if the given array is [1, 2, 3, 4] then the array after one cyclic rotation is [4, 1, 2, 3]. In this article, we are going to learn how to cyclically rotate an array by one position using Python. Using Python insert() and pop() Methods The Python insert() method is used to insert or add an element at the specified index. The index value starts from zero. Following ... Read More

Print Checkboard Pattern of N x N Using Numpy

Yaswanth Varma
Updated on 17-Jun-2025 17:37:02

613 Views

The checkboard pattern is the square grid composed of alternating 0s and 1s, arranged in a way that no two adjacent cells have the same value. It looks like the chessboard, where black and white squares alternate in every row and column. This kind of pattern is not only seen in chess or checkers, but also in image processing, graphics, and visualization, etc. In this article, we are going to learn how to print a checkboard pattern of n*n using numpy. Using Python numpy.indices() Method The numpy.indices() method is used to return the grid of indices with ... Read More

Retrieve Python Module Path

Yaswanth Varma
Updated on 17-Jun-2025 17:36:29

1K+ Views

In Python, every module exists in a specific file path within the file system. Sometimes, we need to find out where the module is located to perform different operations, like debugging or verifying the version of the module. In this article, we will explore how to retrieve the file path of a module. Retrieving Path of a Standard Library Module In this approach, we are going to import the built-in os module, which is part of the Python standard library, and use the 'os.__file__()' to get the absolute path to the actual ".py" or ".pyc" file where the ... Read More

Difference Between dir(), globals() and locals() Functions in Python

Yaswanth Varma
Updated on 17-Jun-2025 17:36:01

756 Views

The Python built-in functions,  dir(), globals(), and locals are used to provide insights into the objects, variables, and identifiers present in various scopes. They might look similar, but each function serves a different purpose and behaves differently depending on where and how it is used. In this article, we will discuss the difference between the dir(), globals(), and locals() in Python. Python dir() Function The Python dir() function is used to list the names in the current local scope or the attributes of an object. If no argument is passed, it returns the list of names ... Read More

Importance of Indentation in Python

Yaswanth Varma
Updated on 17-Jun-2025 17:35:35

1K+ Views

Indentation indicates the spaces or tabs placed at the beginning of a line of code to indicate the block structure. In many programming languages, indentation is used to improve code readability. In Python, indentation is the key part of the syntax. It is used to define the blocks of code, such as loops, conditionals, and functions. If indentation is not used properly in Python, it results in the IndentationError, causing the program to fail. Using without Indentation In this scenario, we are going to use the If-Else statement in the Python program without proper indentation and observe the output. ... Read More

What are Valid Python Identifiers

Yaswanth Varma
Updated on 17-Jun-2025 17:34:18

934 Views

Identifiers are the names used to identify variables, functions, classes, and other objects. A valid identifier helps Python users to assign readable and meaningful names to the elements within the code. To be considered a valid identifier in Python must follow a specific set of rules. Rules For Valid Python Identifiers Following is a list of rules that are to be followed to consider as a valid identifier - The name must begin with the letter (A-Z or a-z) or an underscore. Identifiers cannot be keywords (like if, ... Read More

Advertisements