Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Server Side Programming Articles - Page 677 of 2650
285 Views
To return specified diagonals, use the ma.MaskedArray.diagonal() method in Numpy. Set the Offset of the diagonal from the main diagonal. Can be positive or negative.A masked array is the combination of a standard numpy.ndarray and a mask. A mask is either nomask, indicating that no value of the associated array is invalid, or an array of booleans that determines for each element of the associated array whether the value is valid or not.StepsAt first, import the required library −import numpy as np import numpy.ma as maCreate an array with int elements using the numpy.array() method −arr = np.array([[55, 85, 59, ... Read More
241 Views
In this problem, we are given string str[] of size N and an integer X. Our task is to create a program to print First X vowels from a string.We will print first X vowels from the string and if less than X vowels are present, print -1.Let's take an example to understand the problem, Input: str = "learn C programming language", X = 5 Output: e, a, o, a, i Vowels are a, e, i, o, uSolution ApproachA simple solution to the problem is by traversing the string character by charter. And storing all the vowels of the string ... Read More
195 Views
In this problem, we are given an array of string str[] of size N. Our task is to create a program for finding the first string from the given array whose reverse is also present in the same array.Let's take an example to understand the problem, Input: str[] = ["python", "program", "C#", "language", "#C"] Output: C#Solution ApproachOne way to solve the problem is by directly traversing each element of the string array and checking for revere of the string in the remaining array. Return the string if the reverse is found. If the whole array is traversed and no string ... Read More
235 Views
In this problem, we are given a linked list LL of size N. Our task is to create a program for finding non-repeating in linked list.Linked list is a sequence of data structures, which are connected together via links.Let's take an example to understand the problem, Input: LL = 4 => 6 => 2 => 4 => 1 => 2 => 6 => 5 Output: 1Explanation −The elements with a single occurrence frequency are 1 and 6. Out of these 1 occurred first in the linked list. Solution ApproachAn approach to solve the problem is by creating a hash table ... Read More
1K+ Views
In this problem, we are given an array arr[] consisting of N integer values and a window of size N. Our task is to create a program for finding the first negative integer in every window of size k. We will be printing the first negative number if it exists otherwise print 0, denoting no negative exists.Let's take an example to understand the problem, Input: arr[] = {-2, 2, -1, 4, 3, -6}, k = 2 Output: -2, -1, -1, 0, -6Explanation −Size of window k = 2, {-2, 2}, first negative is -2 {2, -1}, first negative is -1 ... Read More
331 Views
In this problem, we are given an array arr[] consisting of N numbers and an integer value x. Our task is to create a program for finding the first element greater than or equal to X in the prefix sum of N numbers using Binary Lifting.Prefix Sum of elements of an array is an array whose each element is the sum of all elements till that index in the initial array.Example − array[] = {5, 2, 9, 4, 1}prefixSumArray[] = {5, 7, 16, 20, 21}Let's take an example to understand the problem, Input: arr[] = {5, 2, 9, 4, 1}, ... Read More
245 Views
In this problem, we are given an array arr[] of integer elements. Our task is to create a program to find the Floor of every element in the same array. If the floor of an element exists, we will print the floor otherwise print -1.Floor of an element in array is the closest element which is smaller than or equal to the element in the array.Let’s take an example to understand the problemInput: arr[] = {3, 1, 5 ,7, 8, 2} Output: 2 -1 3 5 7 1Solution ApproachAn approach to solve the problem is by using nested loops. One ... Read More
561 Views
In this problem, we are given a sorted array arr[] and an integer value x. Our task is to create a program to find the floor in a sorted array.Floor of X in sorted array arr is the largest element of the array arr[] which is smaller than or equal to x.Let’s take an example to understand the problemInput: arr[] = {2, 5, 6, 8, 9, 12, 21, 25}, x = 10 Output: 9Explanation − In the above array 9 is the largest number which is smaller than or equal to 10.Solution ApproachA simple solution to the problem is directly ... Read More
603 Views
In this problem, we are given a directed graph represented as an adjacency list. Our task is to create a program for finding the path from one vertex to rest using BFS.BFS(Breadth First Search) is an algorithm that traverses a graph in a breadthward motion and uses a queue to remember to get the next vertex to start a search, when a dead end occurs in any iteration.Let's take an example to understand the problem,Input −OutputSA
493 Views
In this problem, we are given a N*N matrix mat[]. Our task is finding the maximum square sub-matrix with all equal elements.In this problem, we need to find the maximum size of a sub-matrix from the given matrix whose all elements are the same.Let's take an example to understand the problem, Input: mat[][] = {{1, 2, 1}, {1, 2, 2}, {2, 2, 2}} Output: 2Explanation −matrix a11, a12, a21, a22 is of size 2X2 and forms a sub-matrix with all equal elements. Solution ApproachA simple solution to the problem is by traversing all the elements of the matrix and then ... Read More