- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 1082 Articles for Go Programming
443 Views
ExamplesInput Array = [1, 3, 5, 7, 8, 9], sum = 11 => (3, 8)Approach to solve this problemStep 1: Define a method that accepts an array and sum.Step 2: Define a mapping variable, type map[int]int.Step 3: Iterate the given array as i.Step 4: If key in mapping sum-arr[i] is not present, then mapping[arr[i]]=i.Step 5: If present, then print “pair is found”.Step 6: At the end, print that “pair not found”.ProgramLive Demopackage main import "fmt" func findSumPair(arr []int, sum int){ mapping := make(map[int]int) for i:=0; i
185 Views
ExamplesInput Array = [1, 3, 5, 7, 8, 9], sum = 11 => (3, 8)Approach to solve this problemStep 1: Define a method that accepts an array and sum.Step 2: Sort the given array, declare low:=0 and high:=size-1 variables.Step 3: Iterate a for loop until low sum, then high--.Step 5: At the end, print “pair not found”.ProgramLive Demopackage main import ( "fmt" "sort" ) func findSumPair(arr []int, sum int){ sort.Ints(arr) low := 0 high := len(arr) - 1 for low
388 Views
ExamplesInput Array = [4, 1, 6, 8, 7, 2, 3], sum = 11 => (4, 7) or (8, 3)Approach to solve this problemStep 1: Define a method that accepts an array and sum.Step 2: Iterate from 0 to n as i.Step 3: Again, iterate a for loop from i+1 to n-1 as j.Step 4: If arr[i] + arr[j] == sum, then return arr[i] and arr[j].Step 5: At the end, print that pair not found.ProgramLive Demopackage main import ( "fmt" ) func findSumPair(arr []int, sum int){ for i:=0; i
442 Views
ExamplesInput Array = [1, 3, 4, 3, 2, 3, 4, 0, 2]Element13420Frequency13221Approach to solve this problemStep 1: Define a method that accepts an array.Step 2: Define a map, where key would be the array’s elements and the starting value is 0.Step 3: Start iterating the input array. If an element is present in the map, then increment the count.Step 4: If the element is not present in the map, then store in map and make its value 1.ProgramLive Demopackage main import ( "fmt" ) func findFrequencyOfArray(arr []int){ frequency := make(map[int]int) for _, item := range arr{ ... Read More
Write a Golang program to check whether a given array is sorted or not (Using Bubble Sort Technique)
273 Views
ExamplesInput arr = [7, 15, 21, 26, 33] => Array is already sorted.Input arr = [7, 5, 1, 6, 3] => Array is not sorted.Approach to solve this problemStep 1: Iterate the array from the 0th index to n-1.Step 2: Iterate the array from the 0th index to n-1-i, where i is the index of the above loop.Step 3: If swap is not taking place in the first iteration, then print that “array is already sorted”.Step 4: If swap occurs, then print “array is not sorted”.ProgramLive Demopackage main import "fmt" func checkSortedArray(arr []int){ sortedArray := true for i:=0; i
449 Views
Approach to solve this problemStep 1: Iterate the array from the 0th index to n-1, where n is the size of the given array.Step 2: Declare low=0th index and high=n-1. Start a for loop till low is lesser than high.Step 3: Find mid=(low+high)/2, if the element at the middle is equal to key, then return mid index.Step 4: If the element at mid is greater than the key, then make high = mid.Step 5: If the element at mid is lesser than the key, then make low = mid + 1.Step 6: If key is not present in the given ... Read More
434 Views
Definition: Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in the wrong order.ExamplesInput arr = [7, 5, 1, 6, 3]1st iteration => swap(7, 5) => swap(7, 1) => swap(7, 6) => swap(7, 3) => [5, 1, 6, 3, 7]2nd iteration => [1, 5, 3, 6, 7]3rd iteration => [1, 3, 5, 6, 7]4th iteration => [1, 3, 5, 6, 7]5th iteration => [1, 3, 5, 6, 7]Approach to solve this problemStep 1: Iterate the array from 0th index to n-1.Step 2: Iterate the array from the 0th index to n-1-i, ... Read More
2K+ Views
ExamplesInput num1=3 and num2=8 => Prime numbers are: 3, 5, 7Input num1=8 and num2=23 => Prime numbers are: 11, 13, 17, 19, 23Approach to solve this problemStep 1: Define a function that accepts two numbers, num1 and num2, type is int.Step 2: Iterate between num1 and num2.Step 3: If the number is prime, then print that number, else break.ProgramLive Demopackage main import ( "fmt" "math" ) func printPrimeNumbers(num1, num2 int){ if num1
189 Views
ExamplesIn the Input array, arr = [2, 4, 6, 7, 8, 1, 2]Frequency of 2 in given array is 2Frequency of 7 is 1Frequency of 3 is 0.Approach to solve this problemStep 1: Define a function that accepts an array and a numStep 2: Declare a variable count = 0.Step 3: Iterate the given array and increase the count by 1 if num occurs in the array.Step 4: Print count for the given num.ProgramLive Demopackage main import "fmt" func findFrequency(arr []int, num int){ count := 0 for _, item := range arr{ if item == ... Read More
2K+ Views
ExamplesInput decimal_num = 13 => Output = 8+4+1 => 1101Input decimal_num = 11 => Output = 8+2+1 => 1011Approach to solve this problemStep 1: Define a function that accepts a decimal number, decimal_num, type is int.Step 2: Define an array to store the remainder while dividing decimal number by 2.Step 3: Start a for loop until the decimal number becomes 0.Step 4: Print the binary array in reverse order.ProgramLive Demopackage main import ( "fmt" ) func decimalToBinary(num int){ var binary []int for num !=0 { binary = append(binary, num%2) ... Read More
To Continue Learning Please Login
Login with Google