Find a Node in Linked List Send Feedback You have been given a singly linked list of integers. Write a function that returns the index/position of integer data denoted by 'N' (if it exists). Return -1 otherwise. Note : Assume that the Indexing for the singly linked list always starts from 0. Input format : The first line contains an Integer 'T' which denotes the number of test cases. The first line of each test case or query contains the elements of the singly linked list separated by a single space. The second line contains the integer value 'N'. It denotes the data to be searched in the given singly linked list. Remember/Consider : While specifying the list elements for input, -1 indicates the end of the singly linked list and hence -1 would never be a list element. Output format : For each test case, return the index/position of 'N' in the singly linked list. Return -1, otherwise. Output for every test case will be printed in a separate line. Not...
An integer matrix of size (M x N) has been given. Find out the minimum cost to reach from the cell (0, 0) to (M - 1, N - 1). From a cell (i, j), you can move in three directions: 1. ((i + 1), j) which is, "down" 2. (i, (j + 1)) which is, "to the right" 3. ((i+1), (j+1)) which is, "to the diagonal" The cost of a path is defined as the sum of each cell's values through which the route passes. Input format : The first line of the test case contains two integer values, 'M' and 'N', separated by a single space. They represent the 'rows' and 'columns' respectively, for the two-dimensional array/list. The second line onwards, the next 'M' lines or rows represent the ith row values. Each of the ith row constitutes 'N' column values separated by a single space. Output format : Print the minimum cost to reach the destination. Constraints : 1 <= M <= 10 ^ 2 1 <= N <= 10 ^ 2 Time Limit: 1 sec Samp...
Given an undirected graph G(V,E), check if the graph G is connected graph or not. Note: 1. V is the number of vertices present in graph G and vertices are numbered from 0 to V-1. 2. E is the number of edges present in graph G. Input Format : The first line of input contains two integers, that denote the value of V and E. Each of the following E lines contains two integers, that denote that there exists an edge between vertex a and b. Output Format : The first and only line of output contains "true" if the given graph is connected or "false", otherwise. Constraints : 0 <= V <= 1000 0 <= E <= (V * (V - 1)) / 2 0 <= a <= V - 1 0 <= b <= V - 1 Time Limit: 1 second Sample Input 1: 4 4 0 1 0 3 1 2 2 3 Sample Output 1: true Sample Input 2: 4 3 0 1 1 3 0 3 Sample Output 2: false Sample Output 2 Explanation The graph is not connected, even though vertices 0,1 and 3 are connected to each other but there isn’t any path from vertices 0,1,3 to vertex...
Comments
Post a Comment