We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Tutorials
- 30 Days of Code
- Day 14: Scope
- Discussions
Day 14: Scope
Day 14: Scope
+ 0 comments If in Typescript:
Add this to main:
const qtyItens = readLine() const element: number[] = readLine().split(' ').map((e) => parseInt(e)) const d = new Difference(element) d.computeDifference() const maxDiff = d.maximumDifference console.log(maxDiff)
+ 0 comments python 3
`# Add your code here class Difference: def init(self, a): self.__elements = a
def computeDifference(self): self.__elements.sort() self.maximumDifference = self.__elements[-1] - self.__elements[0]
End of Difference`
+ 0 comments Easy Peasy Python!
def computeDifference(self): self.__elements.sort() self.maximumDifference = self.__elements[-1] - self.__elements[0]
+ 0 comments python code
class Difference: def init(self, a): self.__elements = a
# Add your code here def computeDifference(self): dif = 0 for i in self.__elements: for j in self.__elements: new_dif = i -j if new_dif>dif: dif=new_dif self.maximumDifference=dif
End of Difference class
_ = input() a = [int(e) for e in input().split(' ')] d = Difference(a) d.computeDifference()
print(d.maximumDifference)
d = Difference(a) d.computeDifference()
print(d.maximumDifference)
+ 0 comments PHP
function __construct($arr){ $this->elements= $arr; $this->maximumDifference=0; } function ComputeDifference(){ foreach($this->elements as $i=>$v){ if($i+1<count($this->elements)){ $shift = array_slice($this->elements,$i+1); foreach($shift as $p){ $this->maximumDifference = $this->maximumDifference < abs($v - $p)?abs($v - $p): $this->maximumDifference; } } } }
Load more conversations
Sort 1068 Discussions, By:
Please Login in order to post a comment