Day 28 — Jewels and Stones

Day 28 — Jewels and Stones

100 Days to Amazon

Image for post

Photo by Artem Beliaikin on Unsplash

Out of Free Stories? Here is my Friend Link.

Introduction

Hey Guys, Today is day 28 **of the challenge that I took. Wherein I will be solving every day for 100 days the [programming questions](https://www.java67.com/2018/05/top-75-programming-interview-questions-answers.html) that have been asked in previous interviews.**

You have a bonus at the end if you keep reading. You can find out the companies that have asked these questions in real interviews.

All these problems are taken from the following [e-book_](https://www.amazon.com/dp/B081969QH5/ref=cm_sw_r_cp_apa_i_wqVZDbCVY8RV6). 🎓_

This is completely free 🆓 if you have an amazon kindle subscription.

This e-book contains 100 coding problems that have been asked in top tech interview questions. It also has a guide to solving all the problems in 200+ ways. **These problems I assure you** has been asked in previous interviews.

You have to decide whether you want to go** unprepared *for a tech interview or go ahead and **quick search for this guide *to solve the 100 problems.

Begin Your ascent to greatness

Day 28 — Jewels and Stones

AIM🏹

You’re given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S is a type of stone you have. You want to know how many of the stones you have are also jewels.

The letters in J are guaranteed distinct, and all characters in J and S are letters. Letters are case sensitive, so "a" is considered a different type of stone from "A".

Example

Input: J = "aA", S = "aAAbbbb"
Output: 3

Input: J = "z", S = "ZZ"
Output: 0

Code👇

class Solution {
        public int numJewelsInStones(String J, String S) {

            Map<Character, Integer> map = new HashMap<Character, Integer>();

            for(int i=0; i < J.length(); i++)
            {

                map.put(J.charAt(i), 1);

            }
            int count =0;
            for(int i=0; i<S.length(); i++)
            {
                if(map.containsKey(S.charAt(i)))
                {
                    count++;
                }

            }
            return count;

        }
    }

Author: Akshay Ravindran

Algorithm👨‍🎓

  1. Create a *Hashmap *to store the Stones. Create a counter that stores the result.
  2. Iterate through the String.
  3. For each character check if the *hashmap *contains that character using *ContainsKey *function.
  4. If it contains, *Increase *the counter.
  5. Else, go to the next character.
  6. Return the counter value at the end of the String. 🔚

programming java coding software-development interview

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Offshore Software Development - Best Practices

To make the most out of the benefits of offshore software development, you should understand the crucial factors that affect offshore development.

5 Core Criteria for Selecting Software Development Company - TopDevelopers.co

Check out these five criteria for the selection of your software vendor, and you will never regret having the wrong quality product made for you.

3 Best Programming Languages for Java Developers

In this article, I’ll share 3 JVM Programming languages Java programmers can learn and why you should learn them. Being a Polyglot developer is of good quality and often valued highly in interviews.

How to Install OpenJDK 11 on CentOS 8

What is OpenJDK? OpenJDk or Open Java Development Kit is a free, open-source framework of the Java Platform, Standard Edition (or Java SE).

How to Prepare for a Coding Interview in 8 Weeks

As of this writing, the market is tough. We’ve been hit hard with a deadly pandemic that left thousands of people unemployed. It’s layoffs everywhere and the companies are being conservative when it comes to hiring.