Skip to content

Instantly share code, notes, and snippets.

View basharkhan6's full-sized avatar
🎯
Focusing

Abul Basar basharkhan6

🎯
Focusing
View GitHub Profile
{
"countries": [
{
"country": "Afghanistan",
"states": ["Badakhshan", "Badghis", "Baghlan", "Balkh", "Bamian", "Daykondi", "Farah", "Faryab", "Ghazni", "Ghowr", "Helmand", "Herat", "Jowzjan", "Kabul", "Kandahar", "Kapisa", "Khost", "Konar", "Kondoz", "Laghman", "Lowgar", "Nangarhar", "Nimruz", "Nurestan", "Oruzgan", "Paktia", "Paktika", "Panjshir", "Parvan", "Samangan", "Sar-e Pol", "Takhar", "Vardak", "Zabol"]
},
{
"country": "Albania",
"states": ["Berat", "Dibres", "Durres", "Elbasan", "Fier", "Gjirokastre", "Korce", "Kukes", "Lezhe", "Shkoder", "Tirane", "Vlore"]
},
// Problen 1
private static int[] twoSum(int[] arr, int target) {
HashMap<Integer, Integer> visited = new HashMap<>(); // num -> idx
for (int i=0; i< arr.length; i++) {
int required = target-arr[i];
if (visited.containsKey(required)) {
return new int[] {visited.get(required), i};
}
visited.put(arr[i], i);
}