ABAG - Go Task

ABAG - Go Task

Problem Statement

Jimmy owns a garden in which he has planted N trees in a row. After a few years, the trees have grown up and now they have different heights.

Jimmy pays much attention to the aesthetics of his garden. He finds his trees aesthetically pleasing if they alternately increase and decrease in height (..., shorter, taller, shorter, taller, ...).

Note that two adjacent trees cannot have equal heights. It may turn out that some trees have to be cut out, in order to keep the remaining trees aesthetically pleasing. However, there is a legal restriction that allows a gardener to cut out at most one tree in his possession. In how many ways can Jimmy cut out exactly one tree, so that the remaining ones are aesthetically pleasing?

Write a function:

func Solution(A []int) int

that, given an array A consisting of N integers, where A[K] denotes the height of the K-th tree, returns the number of ways of cutting out one tree, so that the remaining trees are aesthetically pleasing. If it is not possible to achieve the desired result, your function should return −1. If the trees are already aesthetically pleasing without any removal, your function should return 0.

Examples:

  1. Given A = [3, 4, 5, 3, 7] your function should return 3:
  • You can remove A[0] so the sequence becomes [4, 5, 3, 7];
  • You can remove A[1] so the sequence becomes [3, 5, 3, 7];
  • You can remove A[2] so the sequence becomes [3, 4, 3, 7].
  1. Given A = [1, 2, 3, 4] your function should return −1, since there is no single tree that Jimmy can cut out that would leave the rest of the trees looking aesthetically pleasing.

  2. Given A = [1, 3, 1, 2] your function should return 0, since the trees are already aesthetically pleasing and no removal is needed.

Assume that:

  • N is an integer within the range [4..200];
  • each element of array A is an integer within the range [1..1,000].

Solution

  • The problem is solved by creating subarrays of the original array and check whether they are aesthetically pleasing.
  • Test cases can be found in main_test.go, Feel free to add more cases there and verify the solution.
Owner
Krishna Upadhyaya
Trying to understand the decentralized world!
Krishna Upadhyaya
Similar Resources

Prismforce-task - Assignment to test fundamental knowledge for Prism Force

Technical Assignment Assignment to test fundamental knowledge for Prism Force. T

Feb 15, 2022

Job queuing service and async task runner.

Valet Stateless Go server responsible for running tasks asynchronously and concurrently. Overview Job Pipeline Architecture Installation Configuration

Dec 22, 2022

ABAG - The implementation for the alternating trees problem specified in the task

ABAG - GO task This repo contains the implementation for the alternating trees p

Jan 6, 2022

Task Timer (tt) is a dead simple TUI task timer

Task Timer (tt) is a dead simple TUI task timer

tasktimer Task Timer (tt) is a dead simple TUI task timer Usage To get started, just run tt: tt You'll be presented with something like this: You can

Dec 21, 2022

GTA(Go Task Async) is a lightweight reliable asynchronous task and transaction message library for Golang

GTA (Go Task Async) is a lightweight and reliable asynchronous task and transaction message library for by golang.

Jun 4, 2022

tasq is a simple HTTP-based task queue. Each task is represented as a string

tasq tasq is a simple HTTP-based task queue. Each task is represented as a string (it could be anything). Tasks are pushed to the queue via an HTTP en

Nov 3, 2022

Gotask - A simple task queue is stripped when the program is written to achieve the task delivery function

Gotask - A simple task queue is stripped when the program is written to achieve the task delivery function

gotask The simple task queue is stripped when the program is written to achieve

Feb 14, 2022

Realize is the #1 Golang Task Runner which enhance your workflow by automating the most common tasks and using the best performing Golang live reloading.

Realize is the #1 Golang Task Runner which enhance your workflow by automating the most common tasks and using the best performing Golang live reloading.

#1 Golang live reload and task runner Content - ⭐️ Top Features - 💃🏻 Get started - 📄 Config sample - 📚 Commands List - 🛠 Support and Suggestions

Jan 6, 2023

Concurrent task runner, developer's routine tasks automation toolkit. Simple modern alternative to GNU Make 🧰

Concurrent task runner, developer's routine tasks automation toolkit. Simple modern alternative to GNU Make 🧰

taskctl - concurrent task runner, developer's routine tasks automation toolkit Simple modern alternative to GNU Make. taskctl is concurrent task runne

Dec 14, 2022

Asynq: simple, reliable, and efficient distributed task queue in Go

Asynq: simple, reliable, and efficient distributed task queue in Go

Asynq Overview Asynq is a Go library for queueing tasks and processing them asynchronously with workers. It's backed by Redis and is designed to be sc

Dec 30, 2022

Machinery is an asynchronous task queue/job queue based on distributed message passing.

Machinery is an asynchronous task queue/job queue based on distributed message passing.

Machinery Machinery is an asynchronous task queue/job queue based on distributed message passing. V2 Experiment First Steps Configuration Lock Broker

Jan 7, 2023

The Todo List / Task Manager for Geeks in command line

The Todo List / Task Manager for Geeks in command line

The CLI To-Do List / Task Manager for Geeks 🧑‍💻 Developer / DevOps / Sysadmin? A command line hero? 💻 Live with the dark terminal? 📝 Think in Mark

Dec 15, 2022

Build system and task runner for Go projects

Build system and task runner for Go projects

Gilbert is task runner that aims to provide declarative way to define and run tasks like in other projects like Gradle, Maven and etc.

Dec 21, 2022

Distributed Task Scheduling System|分布式定时任务调度平台

Distributed Task Scheduling System|分布式定时任务调度平台

Crocodile Distributed Task Scheduling System English | 中文 Introduction A distributed task scheduling system based on Golang that supports http request

Jan 5, 2023

Go based task runner

Grift Grift is a very simple library that allows you to write simple "task" scripts in Go and run them by name without having to write big main type o

Nov 21, 2022

go task pool

Task Pool Task Pool 是一个易于使用且高度可配置的 golang类库,专门用于任务的管理&执行,支持自定义次数的重发。 功能特点 线程安全 - task pool 内所有的方法以及暴露的接口都是线程安全的 异步发送 - 调用 PushTask 方法后回立即返回,任务将会被传递到io

Dec 29, 2022

Celery Distributed Task Queue in Go

Celery Distributed Task Queue in Go

gocelery Go Client/Server for Celery Distributed Task Queue Why? Having been involved in several projects migrating servers from Python to Go, I have

Jan 1, 2023

Machinery is an asynchronous task queue/job queue based on distributed message passing.

Machinery is an asynchronous task queue/job queue based on distributed message passing.

Machinery Machinery is an asynchronous task queue/job queue based on distributed message passing. V2 Experiment First Steps Configuration Lock Broker

Dec 24, 2022

Realize is the #1 Golang Task Runner which enhance your workflow by automating the most common tasks and using the best performing Golang live reloading.

Realize is the #1 Golang Task Runner which enhance your workflow by automating the most common tasks and using the best performing Golang live reloading.

#1 Golang live reload and task runner Content - ⭐️ Top Features - 💃🏻 Get started - 📄 Config sample - 📚 Commands List - 🛠 Support and Suggestions

Dec 31, 2022
My Simple Instagram-Clone API task submission, conducted by Appointy for internship shortlisting.

go-pointy Go-Pointy is a simple Instagram API Clone, made using GoLang. I had tried my best to not be lazy and finish the tasks, as a beginner to the

Jul 25, 2022
The task given by Appointy completed to develop APIs for a basic version of Instagram.

✨ Instagram APIs ✨ The task given by Appointy completed to develop APIs for a basic version of Instagram. Create an User Get User by Id Create a Post

Oct 9, 2021
The task is to develop a basic version of a Instagram.
The task is to develop a basic version of a Instagram.

Golang-api-task Developer: Mukka Deepak The task is to develop a basic version of aInstagram. You are only required to develop the API for the system.

Oct 23, 2021
Instagram clone as Appointy task
Instagram clone as Appointy task

Instagram Backend Clone Task for Appointy Internship 2021 Explore the docs » View Demo · Report Bug · Request Feature Table of Contents About the Proj

Oct 11, 2021
Recruitment task.

Clients-emails project. Description. Microservice that stores clients and send them emails based on mailing ID. The service uses Go and PostgreSQL. Bo

Nov 24, 2021
A Google interview task my friend told me about.

deriving π given a normal distribution Try it yourself: package main import ( "fmt" "github.com/cpmech/gosl/rnd" ) // normal returns a number acc

Dec 16, 2021
Support variable parameters task send worker

go-worker-pool Support variable parameters task send worker 调用方式 go get github.com/214200196/gwp/v1 import ( "fmt" "github.com/214200196/gwp/v1" "

Dec 16, 2021
Stq - Simple Task Queue with REST API

stq Simple Tasks Queue with HTTP API Environments list: Variable Value BACKEND m

Jan 5, 2022
MealPlanr is an application dedicated to the trivial and boring task of meal planning 📅 and generating a shopping list 🛒 .
MealPlanr is an application dedicated to the trivial and boring task of meal planning 📅 and generating a shopping list 🛒 .

MealPlanr is an application dedicated to the trivial and boring task of meal planning ?? and generating a shopping list ?? .

Mar 1, 2022
Run vscode task in command line

vstask Run vscode task in command line install go install "github.com/ttttmr/vstask" usage NAME: vstask - Run vscode task in command line USAGE:

Jul 1, 2022