# はじめに

こんにちは、はじめまして、もしくはお久しぶりです。今年の3月からeureka SREチームでエンジニアをやっている @fukubaka0825 a.k.a nari です。

# Description

Design a class to find the kth largest element in a stream. Note that it is the kth largest element in the sorted order, not the kth distinct element.

Your `KthLargest` class will have a constructor which accepts an integer `k` and an integer array `nums`, which contains initial elements from the stream. For each call to the method `KthLargest.add`, return the element representing the kth largest element in the stream.

Example:

`int k = 3;int[] arr = [4,5,8,2];KthLargest kthLargest = new KthLargest(3, arr);kthLargest.add(3);   // returns 4kthLargest.add(5);   // returns 5kthLargest.add(10);  // returns 5kthLargest.add(9);   // returns 8kthLargest.add(4); …`

# Description

Given a string containing just the characters `'('`, `')'`, `'{'`, `'}'`, `'['` and `']'`, determine if the input string is valid.

An input string is valid if:

1. Open brackets must be closed by the same type of brackets.
2. Open brackets must be closed in the correct order.

Note that an empty string is also considered valid.

Example 1:

`Input: "()"Output: true`

Example 2:

`Input: "()[]{}"Output: true`

Example 3:

`Input: "(]"Output: false`

Example 4:

`Input: "([)]"Output: false`

Example 5:

`Input: "{[]}"Output: true`

# Solution

`/* Approach 1: Stacks */func makeParMap() map[string]string{ parMap := make(map[string]string) parMap["}"] = "{" parMap["]"] = "[" parMap[")"] = "(" return parMap…`

# Description

Given a linked list, determine if it has a cycle in it.

To represent a cycle in the given linked list, we use an integer pos which represents the position (0-indexed) in the linked list where tail connects to. If pos is -1, then there is no cycle in the linked list.

Example 1:

`Input: head = [3,2,0,-4], pos = 1Output: trueExplanation: There is a cycle in the linked list, where tail connects to the second node.`

Example 2:

`Input: head = [1,2], pos = 0Output: trueExplanation: There is a cycle in the linked list, where tail connects to the first node. …`

# Description

Write a function to find the longest common prefix string amongst an array of strings.

If there is no common prefix, return an empty string `""`.

Example 1:

`Input: ["flower","flow","flight"]Output: "fl"`

Example 2:

`Input: ["dog","racecar","car"]Output: ""Explanation: There is no common prefix among the input strings.`

Note:

All given inputs are in lowercase letters `a-z`.

# Solution

`/*Go Approach 1: Horizontal scanning*//*Time complexity : O(S), where S is the sum of all characters in all strings.*//*Space complexity : O(1). We only used constant extra space. */func longestCommonPrefix(strs []string) string { if len(strs) == 0 {  return "" }// Assume prefixprefix := strs for i := 1; i < len(strs); i++ {  for !strings.HasPrefix(strs[i], prefix) {   prefix = prefix[0:len(prefix)-1]   if len(prefix) == 0 {    return ""   }  } } return prefix}`

# Description

Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.

Example 1:

`Input: 121Output: true`

Example 2:

`Input: -121Output: falseExplanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.`

Example 3:

`Input: 10Output: falseExplanation: Reads 01 from right to left. Therefore it is not a palindrome.`

Coud you solve it without converting the integer to a string?

# Solution

At first, I answered with the following codes. ( It is the same method as I used in solving the 7. Reverse Integer. related article: https://medium.com/@fukubaka0825/go-leetcode-7-reverse-integer-eaba9692c9a

# Description

Given a 32-bit signed integer, reverse digits of an integer.

Example 1:

`Input: 123Output: 321`

Example 2:

`Input: -123Output: -321`

Example 3:

`Input: 120Output: 21`

Note:
Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231, 231 − 1]. For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.

# Solution

This solution code includes 3 steps.

1. pop operation
2. check beforehand whether or not appending push ope would cause overflow.
3. push operation
`/* [Go] Approach 1: Pop and Push Digits & Check before Overflow *///MaxInt32 == 32767func reverse(x int) int {    var rev int    for x != 0 {        //1.pop operation        pop := x % 10        x /= 10                //2.check beforehand whether or not appending push ope would cause overflow.        if ( rev > math.MaxInt32/10 || (rev == math.MaxInt32/10 && pop > 7)){            return 0        }        if ( rev < math.MinInt32/10 || (rev == math.MinInt32/10 && pop < -8)){            return 0        }                //3. …`

# Description

Given an array of integers, return indices of the two numbers such that they add up to a specific target.

You may assume that each input would have exactly one solution, and you may not use the same element twice.

Example:

`Given nums = [2, 7, 11, 15], target = 9,Because nums + nums = 2 + 7 = 9,return [0, 1].`

# Solution

`/* [Go]  1.Brute Force O(n2) */func twoSum(nums []int, target int) []int { for i := 0; i < len(nums); i++{  for j := i + 1; j < len(nums); j++{   if nums[j] == target - nums[i]{    return []int{i,j}   }  } } return nil…`

# At First

Hi, everyone.

I work as a software engineer at Wano Co., Ltd.

This is my first post on medium.

This time, I would like to leave a memorandum about the trouble occurred when I install Go into the alpine image.

# TL;DR

• If you want to install Go on an alpine-based image, use apk instead of wget or curl command

# What I wanted to do

• I want to auto-deploy lambda with apex command on codebuild (CI) with hashicorp / terraform image
• because I wrote lambda script in Go language, it is necessary to install Go in addition to the hashicorp / terraform image . … 