Type Here to Get Search Results !

Andrew and COVID | HackerRank Solution by CodingHumans |

0

Andrew and COVID                            
                                                                                                                                    
Problem

Andrew loves coding and wants to join the fight against COVID-19. He signs up for coding a project which deals with COVID related queries. However, before he could start the project, he has to answer a simple coding problem. The problem is "Given a multi line string consisiting of lowercase alphabets, special characters, digits and spaces how many times can he form the string covid from it"? Andrew can code this out but can you do it faster than him?

Note: Each character can be used only once and he is not required to maintain the order of characters.

Input Format

The input is a multiline string consisting of lowercase alphabets, special charactes, digits and spaces.

Constraints

1 <= length of string <= 100

Output Format

Print an integer which is the total number of times he can form the string "covid" out of the given string.

Note: Each character can be used only once and he is not required to maintain the order of characters.

Sample Input 0

c1o1vd11i1

Sample Output 0

1

Explanation 0

In this sample test case, the string "covid" can only be formed once by the given string hence, the answer is 1.




Solution:

(Java)

import java.util.*;
public class Tej
{
    public static void main(String[] args)
    {
        Scanner in =new Scanner(System.in);
        String str="";
        while(in.hasNext()){
            str+=in.next();
        }
        char[] ch=str.toCharArray();
        ArrayList<Character>ar=new ArrayList<>();
        for(int i=0;i<str.length();i++)
        {
            if(ch[i]=='c'||ch[i]=='o'||ch[i]=='v'||ch[i]=='i'||ch[i]=='d')
            {
                ar.add(ch[i]);
            }
        }
        
       HashMap<Character,Integer>hm=new HashMap<>();
       for(int i=0;i<ar.size();i++)
           {
        if(hm.containsKey(ar.get(i)))
        {
            hm.put(ar.get(i),hm.get(ar.get(i))+1);
        }
        else
        {
            hm.put(ar.get(i),1);
            
        }
    }
    int res=Integer.MAX_VALUE;
    for(Map.Entry<Character,Integer>entry:hm.entrySet())
    {
        res=Math.min(res,entry.getValue());
    }
    System.out.println(res);
    }
    
}


Words From CodingHumans : Don't Just copy paste try to analyze the problem
HAVE A GOOD DAY 😁


Post a Comment

0 Comments

Top Post Ad

Below Post Ad