---
# System prepended metadata

title: Advanced Coding - Alfi Fadel Majid

---

# Advanced Coding - Alfi Fadel Majid 

1) Given two strings, print Yes if he can replicate his second string exactly using whole words from the first string; otherwise, print No.

```
# Sample 1
# inputs: "you are my man", "you are man"
# outputs: yes

# Sample 2
# inputs: "XSGD is the first SGD pegged stablecoin", "XSGD is xfers stablecoin"
# outputs: no
# explantation: no `xfers` in the first string

# Sample
# inputs: "you are my man", "you are my man cool"
# outputs: false```


// Online Java Compiler
// Use this editor to write, compile and run your Java code online
// # Advanced Coding - Alfi Fadel Majid 

// 1) Given two strings, print Yes if he can replicate his second string exactly using whole words from the first string; otherwise, print No.

// # Sample 1
// # inputs: "you are my man", "you are man"
// # outputs: yes

// # Sample 2
// # inputs: "XSGD is the first SGD pegged stablecoin", "XSGD is xfers stablecoin"
// # outputs: no
// # explantation: no `xfers` in the first string

// # Sample 3
// # inputs: "you are my man", "you are my man cool"
// # outputs: false



class HelloWorld {
    static boolean checkStr2 (String str1, String str2) {
        if (str2.toCharArray().length > str1.toCharArray().length) {
            return false;
        }
        
        int[] count = new int[256];
        char []str3 = str1.toCharArray();
        for (int i = 0; i < str3.length; i++) {
            count[str3[i]]++;
        }
        
        char []str4 = str2.toCharArray();
        for (int i = 0; i < str4.length; i++) {
            if (count[str4[i]] == 0) {
                return false;
            }
            count[str4[i]]--;
        }
        
        return true;
    } 
    
    static boolean checkWords (String str1, String str2) {
        String[] arrOfStr1 = str1.split(" ");
        String[] arrOfStr2 = str2.split(" ");
        
        for (String s : arrOfStr2) { 
            if (!arrOfStr1.contains(s)) {
                return false;
            }
        }
        
        // On2
        return true;
    }
    
    public static void main(String[] args) {
        // String str1 = "you are my man";
        // String str2 = "man are you";
        // false
        
        // String str1 = "you are my man";
        // String str2 = "are my man"; 
        // true
        
        // String str1 = "you are my man";
        // String str2 = "era my man";
        // false
        
        // String str1 = "XSGD is the first SGD pegged stablecoin";
        // String str2 = "XSGD is xfers stablecoin";
        
        // String str1 = "you are my man";
        // String str2 = "you are my man cool";
        
        if (checkWords(str1, str2)) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}
