
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
Found 33676 Articles for Programming

573 Views
A list is made up of tuples as its element. In this article we will count the number of unique tuples present in the list.With defaultdictWe treat the given list as a defaultdict data container and count the elements in it using the in condition.Example Live Demoimport collections Alist = [[('Mon', 'Wed')], [('Mon')], [('Tue')], [('Mon', 'Wed')] ] # Given list print("Given list:", Alist) res = collections.defaultdict(int) for elem in Alist: res[elem[0]] += 1 print("Count of tuples present in the list:", res)OutputRunning the above code gives us the following result −Given list: [[('Mon', 'Wed')], ['Mon'], ['Tue'], [('Mon', 'Wed')]] Count of tuples ... Read More

406 Views
The elements in a given list can also be present as another string in another variable. In this article we'll see how many times a given stream is present in a given list.With range and lenWe use the range and len function to keep track of the length of the list. Then use the in condition to find the number of times the string is present as an element in a list. A count variable initialized to zero keeps incrementing whenever the condition is met.Example Live DemoAlist = ['Mon', 'Wed', 'Mon', 'Tue', 'Thu'] Bstring = 'Mon' # Given list print("Given ... Read More

272 Views
Suppose we have an array nums of positive integers, we have to return the longest possible length of an array prefix of given array nums, such that it is possible to delete exactly one element from this prefix so that every number that has appeared in it will have the same frequency. After removing one element if there are no remaining elements, it's still considered that every appeared number has the same frequency (0).So, if the input is like [3, 3, 2, 2, 6, 4, 4, 6], then the output will be 7, So if we remove element 6 from ... Read More

970 Views
We are given two strings. We need to find the count it of the characters in the first string which are also present in a second string.With setThe set function gives us unique values all the elements in a string. We also use the the & operator which finds the common elements between the two given strings.Example Live DemostrA = 'Tutorials Point' uniq_strA = set(strA) # Given String print("Given String", strA) strB = 'aeio' uniq_strB = set(strB) # Given String print("Search character strings", strB) common_chars = uniq_strA & uniq_strB print("Count of matching characters are : ", len(common_chars))OutputRunning the above code gives ... Read More

285 Views
Suppose we have one number n, we have to count how many strings of length n can be formed using these rules − Each character is a lower case vowel Each vowel 'a' may only be followed by an 'e'. Each vowel 'e' may only be followed by an 'a' or 'i'. Each vowel 'i' may not be followed by another 'i'. Each vowel 'o' may only be followed by an 'i' or 'u'. Each vowel 'u' may only be followed by an 'a'. The answer may be too large, so we will find the answer modulo 10^9 + 7.So, ... Read More

727 Views
In this article we will see how to get some selected elements out of a Python list. So we need to design some condition and only the elements satisfying that condition should be picked and their count to be printed.Wit in and sumIn this approach we use in condition to pick the elements and use some to get their count. 1 is used if the element is present else 0 is used for the result of in condition.Example Live DemoAlist = ['Mon', 'Wed', 'Mon', 'Tue', 'Thu'] # Given list print("Given list:", Alist) cnt = sum(1 for i in Alist if i ... Read More

591 Views
In this article we are given a list and a string. We are required to find how many times the given string is present as an element in the list.With CounterThe counter function from collections module will give us the count of each element present in the list. From the counting result we can extract only that account fair the index matches with the value of the element we are searching for.Example Live Demofrom collections import Counter Alist = ['Mon', 'Wed', 'Mon', 'Tue', 'Thu'] elem = 'Mon' # Given list and element print("Given list:", Alist) print("Given element:", elem) cnt = Counter(Alist) ... Read More

498 Views
Suppose there are n servers. And these are numbered from 0 to n-1 connected by an undirected server-to-server connections forming a network where connections[i] = [a, b] represents a connection between servers a and b. All servers are connected directly or through some other servers. Now, a critical connection is a connection that, if that is removed, it will make some server unable to reach some other server. We have to find all critical connections.So, if the input is like n = 4 and connection = [[0, 1], [1, 2], [2, 0], [1, 3]], then the output will be [[1, ... Read More

771 Views
We are given a string and a character. We want to find out how many times the given character is repeated in a given string.With range and lenWe design a for loop to match the character with every character present in the string which are accessed using index. The range and len function helps us determine how many times the matching has to be done when moving from left to right of the string.Example Live DemoAstr = "How do you do" char = 'o' # Given String and Character print("Given String:", Astr) print("Given Character:", char) res = 0 for i in ... Read More

404 Views
Suppose we have two arrays arr1 and arr2, these can store integer numbers. We have to find the minimum number of operations needed to make arr1 strictly increasing. Here, we can choose two indices 0 size of arr2, then -1, otherwise ret - 1)Let us see the following implementation to get better understanding −Example Live Demo#include using namespace std; class Solution { public: int solve(vector& arr1, vector& arr2, int i, int j, int prev, vector& dp){ if (i >= arr1.size()) return 1; j = upper_bound(arr2.begin() + j, ... Read More