Posts

Showing posts from April, 2020

Number of non-unique elements hackerrank - Python

Problem Definition: We have to find here the number of non unique elements (same elements more than 1 times) in an array.So we have to count how many elements occured more than 1 time in the array. For ex: Consider the array    [1,2,1,3,4,4,2] Here "1" is occuring 2 times and "2" is also occuring 2 times and "4"is also occuring 2 times.So the total number of elements is 3. So the output should be 3. Solution: When we take the input of elements in the array we put all the occuring elements in the hasmap or hashtable also parallely we will check if that particular element is occured previously or not,if occured we increment count value. Python Solution: n=int(input("Enter no. of elements")) a=[] hashmap=[] hashmap1=[] count=0 for i in range (0,n):     ele=int(input())     if ele in hashmap and ele not in hashmap1:         count=count+1         hashmap1.append(ele)   ...

Map in c++ - Standard Template Library (STL)

Map in c++ are the containers that stores elements in the form of keys and values in a mapped format. You can use map for solving various problems,like if you want to calculate any element's frequency. Syntax for map in c++: map<type,type> name_of_map; For ex: map<int,int>m1; where,key type is integer            value type is integer            name of map is 'm1' Header file Header file of map in c++ is  #include<map>. Program for counting frequency of elements: #include<iostream> #include<map> using namespace std; int main() { int a[]={1,2,4,19,10,23,1,1,2,4,23,4,4,19}; map<int,int>m1; for(int i=0;i<14;i++) { m1[a[i]]++;                         //counting elements } cout<<"Frequency of  1 is :"<<m1[1]<<endl; cout<<"Frequency ...

How to dynamically allocate array in c ? Search element using binary search

To dynamically allocate array in c we can use malloc() or calloc() functions.What is the working of these functions illustrated below. malloc(): malloc() is used to dynamically allocate array in c in which will give the size how much we want to allocate and can cast to any data type.In malloc() all the memory is uninitialized. Syntax of malloc(): ptr=(cast_type*)malloc(size); where,ptr is a pointer of type of array you want            size is how much size of memory you want For ex: int *ptr; ptr=(int*)malloc(40*sizeof(int)); This will create 80 bytes of integer type because integer is of 2 bytes. calloc(): calloc() is also used for dynamically allocate array in c in which memory is initialized to zero.We have to specify how many blocks we want to allocate. Syntax of calloc(): ptr=(cast_type*)calloc(n,size); where, ptr is a pointer of type of array you want            ...

Top 5 Programming Languages You Should Learn in 2020 [Jobs]

Image
Top 5 Programming Languages You Should Learn in 2020   [Jobs] When we talk about top 5 programming languages , a question arises in our mind for what purpose we are finding those top 5 programming languages. But don't worry here I am giving you the entire knowledge and information about those top 5 programming languages you should learn in 2020. Let's start: Top 5 Programming Languages in 2020 1. Python                                   Python is one of the best programming   languages you can learn in 2020.Python is   open source and the main thing about   python is that it is easy to learn.  If you are a beginner in the field of   programming language,you can start with   python. If you are preparing for job interviews python might be a good option.Python adds a good value to your resume.You can also start a project...