In this problem, we are given a 2-D matrix mat[][] of size n, n being an odd number. Our task is to Find Maximum side length of a square in a Matrix.Problem Description − We need to find the length of the square matrix whose perimeter values are the same and it shares the same center as the matrix.Let’s take an example to understand the problem, Inputmat[][] = { {2, 4, 6, 6, 5}, {1, 7, 7, 7, 3}, {5, 7, 0, 7, 1}, {3, 7, 7, 7, 1}, {2, 0, 1, 3, 2} }Output3Solution ... Read More
When it is required to find the intersection of data in tuple records, a list comprehension can be used.The list comprehension is a shorthand to iterate through the list and perform operations on it.A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on).A list of tuple basically contains tuples enclosed in a list. Below is a demonstration of the same −ExampleLive Demomy_list_1 = [('Hi', 1) , ('there', 11), ('Will', 56)] my_list_2 = [('Hi', 1) ,('are', 7) ,('you', 10)] print("The first list is : ") print(my_list_1) print("The ... Read More
In this problem, we are given n houses with some values in them. Our task is to Find the maximum possible stolen value from houses.Problem Description − We have an array houses[] that consist of the values that are in each house. A thief robs the houses but he cannot steal from two adjacent houses as neighbours know about the theft. We need to find the maximum possible value that can be stolen by the thief from the house without getting caught.Let’s take an example to understand the problem, Inputhouses[] = {5, 2, 1, 6, 7, 9, 4, 3}Output23ExplanationThe max ... Read More
When it is required to check if a tuple and a list are identical, i.e they contain same elements, a simple loop can be used.A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on).Below is a demonstration of the same −ExampleLive Demomy_tuple_1 = ('Hi' , 'there', 'Will') my_list = ['How' ,'are' ,'you'] print("The tuple is : ") print(my_tuple_1) print("The list is : ") print(my_list) my_result = True for i in range(0, len(my_list)): if(my_list[i] != my_tuple_1[i]): my_result = False ... Read More
When it is required to find common words among the tuple strings, the 'join' method, the 'set' method, the '&' operator and the 'split' method is used.The 'join' method can be used to join multiple values based on a specific value, Python comes with a datatype known as 'set'. This 'set' contains elements that are unique only. The set is useful in performing operations such as intersection, difference, union and symmetric difference.The 'split' function splits the given data into multiple sections depending on the value on which it needs to be split.The '&' operator performs multiplication, i.e AND operation.Below is ... Read More
When it is required to concatenate multiple tuples, the '+' operator can be used. A tuple is an immutable data type. It means, values once defined can't be changed by accessing their index elements. If we try to change the elements, it results in an error. They are important contains since they ensure read-only access.The '+' operator can be used to add numeric values or concatenate strings.Below is a demonstration of the same −ExampleLive Demomy_tuple_1 = (11, 14, 0, 78, 33, 11) my_tuple_2 = (10, 78, 0, 56, 8, 34) print("The first tuple is : ") print(my_tuple_1) print("The second ... Read More
In this problem, we are given a square matrix mat[][] of size m X n with each element either 0 or 1. If an element has value 1, this means it is connected, if the value is 0, this means it is not-connected. Our task is to find the maximum path length in a binary matrix.Problem Description − To solve the problem, we need to find the largest length path on the matrix, which means all 1 elements in the matrix. Before finding the path, we will convert at-most one 0 to 1.Let’s take an example to understand the problem, ... Read More
When it is required to remove similar element rows in a tuple matrix, the list comprehension and the 'all' method can be used.The list comprehension is a shorthand to iterate through the list and perform operations on it.The 'all' method checks to see if all the values inside an iterable are True values. If yes, it returns True, else returns False.Below is a demonstration of the same −ExampleLive Demomy_tuple_1 = ((11, 14, 0), (78, 33, 11), (10, 78, 0), (78, 78, 78)) print("The tuple of tuples is : ") print(my_tuple_1) my_result = tuple(ele for ele in my_tuple_1 if ... Read More
When it is required to convert an N*N tuple into a matrix, a simple loop and the * operator can be used.The * operator can be used to get the product of two values. It can also be used to multiple a single value multiple times and display it on the console.Below is a demonstration of the same −ExampleLive Demomy_tuple_1 = ((11, 14), (0, 78), (33, 11), (10, 78)) print("The tuple of tuple is : ") print(my_tuple_1) N = 4 print("The value of N has been initialized to "+ str(N)) my_result = [] for tup in my_tuple_1 : ... Read More
When it is required to remove duplicates from a tuple, the list comprehension is used.A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on).A list of tuple basically contains tuples enclosed in a list.The list comprehension is a shorthand to iterate through the list and perform operations on it.Below is a demonstration of the same −ExampleLive Demomy_list_1 = [(11, 14), (0, 78), (33, 11), (0, 78)] print("The list of tuple is : ") print(my_list_1) my_unique_list = list(set([i for i in my_list_1])) print("The list of ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP