1.

According to new Traffic rules ,Vehicles with Odd numbers can travel only in odd dates similarly Even numbered vehicles can travel only in Even dates .If any of the vehicle violates the rule will be fined Rs.100. If the same vehicle violates the rule twice the fine amount will be Rs.250 .The task is to calculate the total fine amount to be collected. Example : Input : [12,30,16,15,11] // vehicle number 4 // date output; 200 Explanation: Since 4 is even number only even numbered vehicle can travel in that day .Odd numbered vehicles are fined Rs.100.(11 and 15 violates).Total fine amount will be Rs.200 Constraints: The code should accept input during runtime ,It should satisfies multiple test cases. The code can be of any programming languages except PYTHON . (Java and C programming Recommended ).

Answer»

import java.util.*;public class HelloWorld{     public static void main(String... args){        Scanner s = new Scanner(System.in);        int[] intArray = Arrays.stream(s.nextLine().split(",")).mapToInt(Integer::parseInt).toArray();        int day = s.nextInt();        ArrayList vis = new ArrayList<>();        int amt1 = 0;        int amt2 = 0;        if(day%2==0){            for(int i: intArray){                if(i%2!=0){                    if(vis.contains(i)){                        amt2 = amt2+1;                        amt1 = amt1-1;                    }                    else{                        vis.add(i);                        amt1 = amt1+1;                    }                }            }        }        if(day%2!=0){            for(int i: intArray){                if(i%2==0){                    if(vis.contains(i)){                        amt2 = amt2+1;                        amt1 = amt1-1;                    }                    else{                        vis.add(i);                        amt1 = amt1+1;                    }                }            }        }        int ANS = amt1*100+amt2*250;        System.out.print(ans);     }}Explanation:nothing much to explain.I don't know your standards in programingI wrote code somewhat huge but same can be WRITTEN using hash SET and it solved that will be a good programing but idk you have KNOWLEDGE of hash sets or not so I've written this for a beginner.......



Discussion

No Comment Found