├── SquareNumber ├── README.md ├── NumberSeries.java └── StringSearching.java /SquareNumber: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Bank_of_American_Interview -------------------------------------------------------------------------------- /NumberSeries.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class NumberSeries { 4 | public static void main(String[] args) { 5 | Scanner scanner = new Scanner(System.in); 6 | 7 | while (scanner.hasNextLine()) { 8 | int N = Integer.parseInt(scanner.nextLine()); 9 | int sum = calculateSum(N); 10 | System.out.println(sum); 11 | } 12 | 13 | scanner.close(); 14 | } 15 | 16 | public static int calculateSum(int N) { 17 | int sum = 0; 18 | 19 | for (int i = 1; i <= N; i++) { 20 | if (i % 5 != 0 && i % 7 != 0) { 21 | sum += i; 22 | } 23 | } 24 | 25 | return sum; 26 | } 27 | } -------------------------------------------------------------------------------- /StringSearching.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class StringSearching { 4 | public static void main(String[] args) { 5 | Scanner scanner = new Scanner(System.in); 6 | 7 | while (scanner.hasNextLine()) { 8 | String line = scanner.nextLine(); 9 | String[] parts = line.split(", "); 10 | 11 | if (parts.length != 2) { 12 | System.out.println("false"); 13 | continue; 14 | } 15 | 16 | String text = parts[0]; 17 | String pattern = parts[1]; 18 | 19 | boolean isMatch = isSubstring(text, pattern); 20 | System.out.println(isMatch ? "true" : "false"); 21 | } 22 | 23 | scanner.close(); 24 | } 25 | 26 | public static boolean isSubstring(String text, String pattern) { 27 | int textLen = text.length(); 28 | int patternLen = pattern.length(); 29 | int i = 0; 30 | int j = 0; 31 | 32 | while (i < textLen && j < patternLen) { 33 | if (pattern.charAt(j) == '\\') { 34 | // Check for an escaped asterisk 35 | if (j + 1 < patternLen && pattern.charAt(j + 1) == '*') { 36 | if (i < textLen) { 37 | j += 2; 38 | continue; 39 | } 40 | } 41 | } 42 | 43 | if (pattern.charAt(j) == '*') { 44 | // Match zero or more characters 45 | while (j < patternLen && pattern.charAt(j) == '*') { 46 | j++; 47 | } 48 | 49 | if (j == patternLen) { 50 | return true; // Asterisk at the end matches the rest of the text 51 | } 52 | 53 | while (i < textLen && text.charAt(i) != pattern.charAt(j)) { 54 | i++; 55 | } 56 | } else if (text.charAt(i) == pattern.charAt(j)) { 57 | i++; 58 | j++; 59 | } else { 60 | i = i - j + 1; 61 | j = 0; 62 | } 63 | } 64 | 65 | return j == patternLen; 66 | } 67 | } 68 | --------------------------------------------------------------------------------