خرید بک لینک

Vote count: -4

I have some data such:

Date, item, amountSold

22-3-14, shampoo, 20
22-3-14, polish, 2
23-3-14, noodles, 5
23-3-14, sausage, 5
23-3-15, candy ,20

How would I create an algorithm to find out the greatest volume of sales on a given day. So the most amountSold basically. I was wondering how I would begin to write this algorithm, here's my logic:

for x the date:
    get amountSold
        assign to temp
        if temp is greater than mostSales
            mostSales = temp

I need to somehow incorporate the acknowledgement of the same date selling items

EDIT:

I think I have a solution.. Please comment improvements

char[] previousDate

for x the date:
    if(x == previosDate)
        temp = amountSold + temp
    else
        temp = amountSold


    if temp is greater than mostSales
         mostSales = temp  

asked 9 mins ago

3 Answers

Vote count: 0

You can hash based on the date values.

def MaxSalesOnDay(InputSet):
     hash = []
     maxSales = -infinity
     for items in InputSet:
         if items.date not in hash:
            hash.add(items.date, 0)
         value = hash[items.date]
         hash.update(items.date, value + items.count)
         maxSales = Max(value, maxSales)
     retu maxSales

The hash is part of many mainstream programming languages. Or you can implement one on your own.

answered 2 mins ago

Vote count: 0

Assuming your dates are ordered, you don't need a map:

curDate <- invalid
curAmount <- invalid
bestAmount <- invalid
for x the date:
    if not sameDate(curDate, x)
        curDate = x
        if bestAmount < curAmount
            bestAmount = curAmount
        curAmount <- 0
    curAmount <- curAmount + amountSold

answered 1 min ago

Vote count: -1

A map, sometimes called a dictionary, is an appropriate datastructure for this.

With a map you can map keys to values.

Define a map that maps dates to integers.

Then loop over your data set, find the date in the map, add it if it doesn't exist, and if it does exist, overwrite the value if it is higher than the current value.

Read more:

Map in Java

Dictionary in Python

answered 4 mins ago

برچسب: نویسنده: استخدام کار تاريخ: پنجشنبه 12 فروردين 1395 ساعت: 20:24

صفحه بندی