Hello, Welcome to SSUniTech, so see this side and in this video we are going to see how we can load the data from the JSON file with the nested hierarchy to the CSV file. So what is the JSON with the nested hierarchy? First we need to check about this and after that we will see how we can load that into the CSV file. So let me go into the source file so we can see the data for sales. So here we are having the data for the sales as we can see the SOID, then the sales order date, then the country. After that we are having this nested hierarchy of the JSON. So this is one of the JSON and it is having the data for the item, quantity and value. So this is one of the JSON which is inside the whole JSON. So for example here we are having SOID, SODate, country and under the sales item, quantity and value. So in the CSV file we will be having six columns with the SOID, SODate, country, item, quantity and value. We will not be going to keep the information like we are having here. So how we can convert this we will see in this video. Let me go into the browser and we will try to implement this in practical. This file is already available in the input blob storage and with the name of sales.json as we can see here. Let me go into the SEO data factory and we will try to implement this in practical. So let me try to add a new data flow here. So this data flow let me call this data flow as load from JSON to CSV. Now first we need to add the source. So let me try to create a new data set here. So click on new as your blob storage click on continue and the file which is the JSON file so we can select the JSON file here and click on continue. And here let me call this as data set for the sales underscore JSON format link service we have already created so let me use the same then we need to select the file. So let me try to browse this go to the input folder and after that we can select the file which is the sales dot JSON file. Let me click on OK. Here everything is OK we can click on OK. So this data set will be created. So as we can see everything looks OK. Let me go into the source option and under the source option if you can scroll in the bottom side then we can see the JSON setting. So if we open this then document form which is the document per line but it is area of document because we have the nested JSON under that file. Now let me go and try to check the data. So we will be going to see the data. So as we can see the SOID SO date and country is coming correct but under the sales here if we can click then we can see total three of the sales. So it is having the item quantity and value similarly for the second third. So all these are having data like this. So as of now this data is the complex type of an array. So we need to convert this as an string data type. So how we can do that as we have already discussed about the flattened transformation. So we have to use the flattened transformation to convert this array into the string values. So here we need to select the enrolled by. So under the enrolled by we have to select the sales as we are having this sales column into the source. So we can select this after that here we can see the enrolled root. So here we can also select the sales. So by which we want to unroll this. So let me try to go in the bottom side and here we can see the sales is mapped with the sales. So we don't want to map sales with the sales. So how we can add the item quantity and value. So once we click on this sales then it is having the item. So we can select the item. Let me add another mapping and that mapping will be for quantity. So here we can select the quantity. Similarly let me add another mapping. So this mapping will be for value. So everything is coming from the sales table. So as we can see so let me try to rename this column as item. So now we will be going to have the value for the SOID SO date country item quantity and value. This item quantity and value is coming from the sales. So let me go into the data preview and try to refresh. So we will see the data here. So it should be having six column with the item quantity value SOID SO date and a country. So here as we could see SOID SO date country item quantity and value. So now it is having the data as per expected. Now let me try to add the sync here. So under the sync we will be going to add the data into the output folder of the blob storage. So for that let me try to create a new data set as your blob storage and we want to keep the data into the delimited text file. So we can select click on continue. After that here we need to select the link service. Then we need to browse and here let me go into the output folder and select that first row as header. So we can select this checkbox. Let me click on OK. So delimited text one data set will be created for the destination. Here if we can go into the setting then we can see the option the file name. So we want to keep into the single file. So we have to specify the name so that is for the sales underscore JSON dot CSV something like this. We need to set the single partition and now we can set this. So it will be going to saved. In between let me try to add a new pipeline and under this pipeline as we can see this is saved so we can drag and drop this and we will be going to execute. So once it will be executed your JSON file will be loaded into the CSV file in the output folder of the blob storage. So this is in progress so let me try to refresh it. So as we can see it got executed successfully. Let me go into the Azure blob storage and go to the output folder of this. So here we can go into this container of the output folder and here we should see the file. So we can check sales underscore JSON dot CSV file. So this is the file. If we can go into the edit then we can see the data here everything is coming as expected. So thank you so much for watching this video. In the next video we will be going to convert the CSV file that we have generated in this video into the JSON with a nested hierarchy. So we will do the reverse what we have done in this video. See you in the next video.


It is necessary to consider harms beyond the public health approach. The harms of the dominant drug policy regime are broader. Time has come to a broader understanding of the harms produced by the moralistic condemnation of activity which do not harm others. The dream, or better said, the illusion of a drug-free society, the militarization of the war on drugs. During my presidency, with the advice of various groups, including drug treatment providers and parents, I signed a law to criminalize personal possession of drugs. A decade later, I know that it was a mistake. You have seen the international harm reduction conferences for many years focusing on public health issues. And it took some years before we went back to talk and discuss drug policy issues. What is much more, for me, much more relevant and much more interesting to debate what causes the harm that we are trying to prevent and what we are trying to treat. I used to be a police officer. I'm learning, for instance, that harm reduction is much more than I thought it was. So I'm really grateful for being invited and to be here. There's a big push for compulsory treatment in Thailand. The strategy hasn't really changed since the big war on drugs that happened in 2003. It's still focused on incarceration, forced treatment. For me, the key issue, because we're kind of involved in it, is TB. The whole question of TB amongst injecting drug users. I've just been to a session now and it's the biggest killer of drug users. It's a neglected issue. Scale is important, but quality is also very important, so let's not forget about quality. We have generated so much evidence. We know harm reduction works. However, the major disappointment for me over this decade is that all the funding for harm reduction continues to come in the former Soviet region from external donors. Where there is no funding from external donors such as Lithuania, for example, there is almost no national funding for harm reduction for needle exchange. Financing of harm reduction is for sure the major issue in the region. Global fund is decreasing its funding for middle income countries and the majority of countries in the region are middle income. What we need to be very watchful of is to make sure that austerity measures do not become an excuse for services being cut. I very much hope that we start using sound evidence against irrational drug policy, not only because it's the right thing to do, but because we simply cannot afford to be wasting money. What I learned from this conference is that we should involve definitely the private sector to support harm reduction programs. Harm reduction programs saves lives and the private sector is not excluded from saving lives. The government should take care of adapting laws that allows private sector to benefit from supporting harm reduction programs in every country. How do you see this conference? Have you learned something important you can take home? Every time I come to this conference I learn many things important to take home and trying to relate it to how we can organize better Arab drug users to participate and advocate for their own rights in the Middle East or Arab nations.  It's part of the culture and learning from other people in the world how to maybe circumvent that and deal with that. What's really sort of positive for me from here in this conference is a lot of people who are HIV positive that have a long drug use history are super active and we see them and they're visible and they're taking part, they're speaking out. So, I mean that gives me real hope that even though things in Russia are complicated even though there is significant repression across this region people have the strength and the courage to speak on behalf of their needs, needs of their colleagues and friends. Often we would have things to say and contradict that she will not like, that she may not agree with and that she may object to. However we do not say these things for the sake of being obstreperous or difficult but because the lives, wellbeing, dignity and human rights of our community are ultimately what is at stake in everything that you do. Remember that for many of you this is the job but for us it is quite literally our lives.


I Speedo not We're super excited to have Lennart en jönan with us and you spent decades in management and research positions. And one of the things you've done is that you wrote a book summarizing a lot of the things that you've worked with and seen in research and your experiences and I'll basically just leave the floor to you. I think your slides are here. Big hand for Lennart Franke. En gärning som. Now you hear me. Yeah, very good. Fine thanks and thanks for inviting us. We were happy to be here. It's been a great conference so far. And I will probably refer to some of the presentations we've heard before. Now it's an important thing that Tommy just said. We are one Akademin Jöran, who is a researcher and a lecturer at Uppsala Unastiet, but with a considerable practical experience from before writing his thesis 20 years ago. And I am a practitioner, a reflecting one. I have to say I've spent more than 40 years in a knowledge based service industry banking. I have to say it. Yeah. And 35 years of that in in the most agile of banks. Anyway, I was the CEO for six years at that bank. And we claim therefore that we combine combine theory and good practice when we make our presentations and when we wrote our book together. Now the majority of you come from it as far as I understand it's important therefore to say that what we are presenting what we're talking about is how to scale agile product management and the success that is hat has proved in that area to corporate culture. To management modeling and to governance of companies, both large companies and small and medium sized companies. We are discussing a philosophy for steering whole companies. And as you again said this morning organizational culture is at odds with agile from time to time. And so we have all of us to address the full corporate culture if we want to make full organizational organizations agile. We are anxious also to point out that when you move from a more traditional kind of management model into an agile one, you have to experience terms as that and theory to. We have to have a holistic view on it. You have to be coherent when you do it. It is a problem if you try to move back and forth. You have to be basically consequent when you when you make these changes. Now what we're talking about is how to move from traditional mechanistik. The centralized type of management to do away with typical mechanic mechanistik tools and means because they don't go well with people. They don't go well with people of flesh and blood. That's the basic message in our book. And therefore we try to describe this by using four dimensions. I have it. Det är det. By using four dimensions by dimensions or criteria. Of how to move a whole culture consequently to become more agile. More organic if you want and to make it possible for people to be agile leaders and professional within that framework. The first dimension is to focus on customers more than on only shareholders. That means moving away from the shareholder value philosophy. As it was born in the 1980s. The short sightedness that came from it. Quarterly capitalism as we usually calls it. And move into true customer and market orientation. And to an organization that creates long term relationships with not only the customers and the markets but also with its employees. And the second dimension that we tend to focus on is. To move from and avoid short sighted and to move away from. Having short sighted and unwanted risk being created in an organization by using incentivizing by using intensive for senior people in terms of cash bonuses. But instead stimulate intrinsic motivation. That is the ordinary purpose mastery autonomy. As we would usually call it. I'm quite convinced that gamification is one way of doing it. That's one of the speakers this morning we're talking about. I also find it extremely interesting that a behavioral economist has become one of the Nobel Prize laureates this year. I think that works in the direction that people like ourselves really want to see. I also think that the Bonita Roy's message is important. Why we actually can trust self organization. We have it in us even as part of the evolutionary process. As she said. The third dimension that we look at is. Moving away from minimized moving away from detailed instructions and controls. En inställd move to trusting people's intrinsic driving force to do her and or his best. The wish to be accountable as someone put it this morning. I think it was James Priest. And I also want to remind you and line the importance of what PM IA started to say this morning. The fact that lots of people don't feel well in their organizations these days. There to mechanistik. The too much top down control is one of the important reasons for that. And the fourth dimension that we point to is the need to move away from budgeting. Rolling forecasts financial plans broken down to personal financial targets. And instead assist performance with the relative targets and by benchmarking to comparable competitors actual numbers. That the financial side of what we're talking about her. But only one of the four dimensions when we speak and we will make presentations to audiences where there are lots of controllers and people involved in financial steering processes. This becomes the main topic in this audience. I'm sure that you can evaluate and see the balance between all four of them. Now the important message and the underlying message that we want to underline is that people like ourselves all of us have to convince not only IT officers and product developers. But we have to influence senior managers. We have to influence CEO's directors general in public organizations board members. Låts fairholders even to make this happen. Because it will make them perform better become richer if you want. And to deal with dynamics and competitive markets. Much better. Now you're on these ideas about agile new or old ones. I'm glad you asked me that question because as I said I'm a grumpy old researchers as you know for researchers nothing is ever new. At least not in management. I have a book here a reference burns and stalker 1961. The book is called the management of innovation. And what they do in this book among other things is that they talk about the mechanistik management system under organik management system. Så det är just the organism metaphor. Quite some time ago and it wasn't but Bonita Roy started it all. Probably not these guys either. Probably older. But this is the first I've seen it used in management. Det talk about the talk. Let me just quickly go through it. Det talk about creating motivation through contributing to girls. Instead of through pay. Det talk about cooperation teamwork and interaction. Instead of specialized defined responsibilities. Det talk about extensive horizontal communications instead of hierarchy communication. Det talk about informal organizations. Instead of formal organizations. Det talk about encouragement instead of supervision. External fokus. Instead of internal fokus. And the main the main focus here is on people and culture and not on technology and routines. And if we look at this isn't this slightly similar to what we call agile. Don't you say so 1961. Even I wasn't born like that. So this is here we know we know this that the knowledge is has been known for quite some time. Has it been tested. Yes it has. And now we're going to give you some examples of companies who at least claim that they are very agile. In some cases we know that quite well in some other cases we have to trust what we read. This is new core. It's a steel company. The biggest American steel company and it is managed. Quite similar to a handisbanken where Lena comes from extremely decentralized. Very small headquarter. And they are so decentralized that they double a lot of functions like James warned us about. They do that because they believe in decentralization. They still talk to each other and learn from each other. Det har blivit extremligt successful. Sämt. You probably know about that one. The most democratic organization in the world. Well they actually have a voting system for important business business decisions decisions. One man one vote. Just like Bonita ask for before. Så det är en del har också binda har varit groen extremligt fast. En del har varit successful för många, många års. South West Airlines. That is the biggest American airline. Ryanair basically took all stål. All that strategy from them except one thing. Ryanair wants to have really cheap employees. They don't want to pay much because they are a low cost airline. South West Airlines. They have the best paid employees. How can they do that if they are a low cost airline. They can do that because they have fewer employees. It's as simple as that. And the other big difference to Ryanair is that South West Airlines have the orange top when it comes to customer satisfaction. We all know where Ryanair is. Don't we. We have Virgin or if we should believe them have managed to stick on to the entrepreneurial culture that they had when they started off like a small record company in the early seventies. And they have been extremely successful and they have. Yeah you all know that they have don't have to go in to that. But they say the reason is that they have clinging on to the entrepreneurial culture they had when they started. Even though they have been growing. We have of course handelspanning and we talk a lot about that naturally in the book. So why do we bring all up all those these old cases. We bring them up because they have been doing this successfully for 20 30 for 40 even 45 years. And that sustainability if you can do it for one year or five years or even even 10 years that's fine. But if you can do it for 45 years then it seems like these ideas are actually working. That's at least the way I understand. I may be wrong but I don't think I'm a stubborn bastard. I. Of course we know that there are a lot of people here sitting here working at small it and consultants in firms etc. As agile as these are probably even more agile than these companies. You're also doing really really well and we love you too. We love you too. You don't have to worry about that. But the thing is I think it was James who pointed that that it's easier to be agile when you're young and small than when you're big enough. So the trick is to remain. There will be some point in time when people will say OK. Now we can't work like this anymore. We need to have more structure. We need to have more orderliness. Everybody needs to know what they are supposed to do etc. We can't work like this anymore. This is where you have to stretch keep the rubber band stretch. And this metaphor is from John Valander. You know the old handelsbanken CEO said decentralisation. It's like a rubber band. You have to hold on to both ends of the rubber band. Because if you let one end go it snaps and that means back to centralisation. Back to hierarchy back to bureaucracy etc. Because there is some kind of natural force driving us in that direction. OK. Now I think I'm losing my breath. Do we have more time or what should we do. Maybe we have time for one or two comments from. Ja. Do you have any questions. What do you say Tommy. Was it all clear. I say we start with a big hand in that case. Let's do that first. But there was a question. Thank you. It's gift time. Sorry about that here anyway. All right. Come on. Thank you. Thank you very much. It's very difficult. Please. It is the question was what do you need to do in order to maintain the rubber band stretched in the sense. It is very closely tied to what we said about accepting that the decision to move really move a full organisation over to a more agile management model. It's a very senior one. It has to be made by the CEO supported by the board. And if there are substantial shareholders it has to be anchored with them too. And that means that when you have made this change and unless it would be there only for one or five years as you said. But it would stick for a number of years. It has to be guarded the full time by senior management. So as soon as something goes wrong somewhere in the organisation. It's not allowed to make the decision. We have decentralized too much. We have been too to agile. We don't follow rules or whatever. But you have to stick to the model and deal with the problem with the problem itself individually but not be tempted to go back to a top top managed top down managed model. It's a matter of self discipline when it comes to the managers. Because everybody who is a manager wants to have more control because you are responsible and all that. But you have to reject that. Now I'm not going to give myself more control. I'm going to trust people to do their job. I'm not going to evaluate every detail they do or put in financial rewards for reaching sales targets or whatever. I'm going to trust them to do their job. My job is not to get my fingers in their job. But you come back to the owners several times in your part as well. And you do that in general. So is it a benefit to have passive owners or is it the benefit to have very active owners in your experience? I would say active owners. With the right mindset then. Yeah, yeah, that's true. But owners who know more about the business. It's more likely to let you do your job. Right, but if you have passive owners like on the stock market to really don't know anything about the business. If you get down one quarter with your financial results and the stock rate gets down, they will start thinking about selling. And that creates this short termism we see in lots of companies today. I also think this goes well with active owners, but I also think there is a message for investors in here that the investors need to be more long term and not give in to what I call quarter capitalism. That was partly where I was getting at because if you're in here and you need to have a checklist of things to consider before moving into company A, Y or C or organization, then that is becoming a bigger and bigger topic on the checklist. All right, but you'll stick around. And I mean, I have tons of questions, but we don't have much time for them, I guess. But you'll stick around so we can pick your brains a bit more. All right, thank you very much. Thank you.


It's that time again for us to show you Africa to the world one country at a time Excited, you know why because I'm finally going to my country number 25 Zimbabwe Zimbabwe means a lot to me. I mean Zimbabwe is so special to me You know why because of Robert's Mugabe? We have fought for our land We have fought for our sovereignty small as we are We have won our independence and we are prepared to shed our blood Insustinance and maintenance and protection of that independence Robert Mugabe's wife, I mean first wife Sally was from my region Yeah, so I grew up hearing about Robert's Mugabe Used to be a god for Mugabe any time Mugabe comes to my region Did you know that Mugabe's first son died of malaria? In second day and he was buried in second day And any time Mugabe comes my mom will be the one to guard him and because of that I learned about Robert Mugabe when I was growing up But apart from that when I went to school in China, I had so many classmates from Zimbabwe So I've always wanted to go to Zimbabwe But this is my fourth time trying to enter Zimbabwe My first time when I found myself in Livingston, Zambia, I was deported from Zambia So I couldn't enter Zimbabwe Second time I found myself in Mozambique and when I got to Mozambique I couldn't enter Zimbabwe because COVID got me stuck in Mozambique I couldn't go to Zimbabwe once again Third time I went to South Africa and I wanted to go to Zimbabwe And I got a call from my mom that your sister's wedding, you need to be here on time So I had to abandon my trip to Zimbabwe And then yeah, I come for my sister's wedding but the time is finally now And I always say that ghost time is the best So you know what? I'm going to Zimbabwe finally And listen, I'm not just going to Zimbabwe I'm going to surprise my friend This is the guy that I started my YouTube channel with I don't know if you guys know Tony Lala Tony Lala Tony Lala I'm telling you Tony Lala I'm telling you This was one of my first ever video And I started with this guy from Zimbabwe He doesn't know I'm coming, it's a surprise video So come along with me I'm going to tell you how I'm going to surprise my friend in Zimbabwe Enjoy the trip, stay tuned, grab a chilled beer If you have chilled water, drink it in case you don't drink alcohol And let's go together Thank you The driver is telling me that I look familiar And I'm also saying that he looks familiar I look familiar though Are you not the guy on YouTube? Who makes YouTube videos? Ain't no one Oh really? He's born on Twitter What was the name of his operator? To G Twitter people look at him He's so familiar that I know him in real life The reason why we do travel videos is to inspire you to travel But traveling in Africa is extremely expensive Sometimes I ask myself Why is it so expensive to travel within Africa? You see, I'm going to Zimbabwe One ticket of mine costs $500 And I had to buy three tickets Which makes it worth $1,500 Have you guys asked me What am I going to stay when I get to Zimbabwe? Extremely expensive Have you asked me What am I going to eat when I get to Zimbabwe? You see, so our travels are extremely expensive That's why I always come in here to tell you You have to sponsor us in a way that you can You all know that I love and care about you guys Because I've always wanted you guys to travel along with me So I've been looking for an affordable way to travel within Africa That is when I reach out to our dancer travels But when I reach out to them, they tell me that We don't do African travel And I said do an African travel And me and my audience will make it successful So they decided to organize a package Which is so affordable for you all Check the link in the description and you'll be shocked to know that Your ticket will be taken care of Your accommodation will be taken care of Your food will be taken care of For just an affordable price Check the link in the description Let me know where you want to go with me I will see you all when you get the package Thank you Finally got to Kutukwa International Airport Tevinah 3 And we're heading to Zimbabwe I don't know why Can I tell you guys, I'm super excited once again So check-in is done We're on our way to Addis Ababa We're going to spend a night in Addis And then the next morning we'll fly to Harare Zimbabwe But like I said, I also want to surprise A classmate of mine, a guy who I started YouTube videos with And you know what we did I wouldn't want to call him, yeah Wait a minute, wait a minute Are you done? He's not even online Hey I think we should call him Yeah, he's just ringing Keep recording So the guy's not picking up So far, yeah Hi, mega wish What? Hey man, so I'm giving the parcel to Steven, yeah So he's going to bring you the parcel He's here with me He just want to say hello and then I'll give your number to him So when he gets to Harare, he's going to call you Okay, you want to say hello to him? Hello bro Hi bro, how are you? I'm good, how are you? Yeah, I'm coming to Zimbabwe And I'm landing on Sunday Yeah, I'm landing on Sunday Almost Yeah So should I pick you at the airport? Yeah, you can pick me at the airport That would be cool Okay, okay, okay So you just get my contact From With the manager And then we can be texting on WhatsApp Are you on WhatsApp? Yeah, I'm on WhatsApp Don't worry bro We're going to link up when I get to Zimbabwe I have to board the plane right now So Okay, okay, okay I'll get your contact Okay Tony mega wish Tony mega wish Hey, more garbage sand Alright bro, all the best man Okay, take care, take care Bye He has no idea that the parcel is what am I So yeah, come with me Let's go to Zimbabwe And go surprise my old time friend I hate about planes man Can you share in the comments section Let me know your most terrible turbulence You've experienced Because damn it man I don't even feel like eating the food now The plane is stable now I got my tea Enjoying myself And I decided to play with a world map here And Through my discovery, yeah It's just like the white people came to Africa And they said They discovered Lake Victoria It doesn't make sense So I was also going to come up with a theory I discovered I actually discovered that Africa Is an island It's surrounded by water From So right here At the See, this is the only land So let's pray that this land Break And if this break Or maybe if this switch or switch or whatever Africa is going to be an island We're going to detach ourselves from the rest of the world man But what will happen in the future But I mean, we are almost detached Then the world is still functioning What is wrong with us man You guys knew this already I think Africa is an island Let me know what you think in the comments If you're a fan from Itopia Just let me know in the comments section Yeah Oh wow, it's nice to meet you Nice to meet you too Great I can't recall the number of times I've been to this city I mean, it's one of my favorite cities in Africa I mean, at this Sababa, you all know the new flower I found my flowers in here And believe me or not This city is amazing It's beautiful And I just love it And I believe that If you ever come to Addis Sababa You're also going to love it So yeah, I'm not here because of Addis Sababa Let's stick to the plan Alright, my friend is in Sababa So let's go It's time to go to Harajuku In Zanzibar, you cannot go alone You have to go with another person You know, I want to tell you guys something I feel like the airport is the headquarters Of my YouTube subscribers Because any time I step out I always meet people at the airport Like, oh, I watch your videos And yeah, we are I mean, we know each other for so long It was so long, bro You remember Inshinian? Yeah I actually attended one of your stand-up comedy shows And you won that show Exactly I don't think I won They just decided to give me I'm going to give it to you Because at this point in time Man, I appreciate everything you're doing It's amazing I'm really, really happy you're coming to our country Yeah We have to link up And you'll be surprised How many fans you have from my country What should I expect from Zimbabwe, man? Firstly Saza Saza, do you know what is Saza? Come on I was eating Saza in China, man You don't even have to tell me that Because, you know I had so many Zimbabwean classmates So Saza would... It's also called pop, right? Yeah Thank you Let me tell you something Ndara Ndara Ndara I have heard Jalof rice in China Okay But I think Jalof rice from Kumas is different Saza in Zimbabwe is going to be different Really? Expect the real Saza, okay? Nah, I'm really going to try the real Saza What's Saza you don't know about? There's only one Saza in my country, okay? You know, let me tell you something In Ghana, when you say You've tried Jalof rice It's like you've tried all women Oh Is that what you're trying to say? That is so funny Anyway, yeah It's nice looking up to you Let me tell you something about Zimbabwe When we're in school, yeah You don't need to get to know somebody Before you get to know that it's Zimbabwean Early morning They don't joke with their beer, man And I'm going to Zimbabwe I'm going to see that more often, man He said the only way to tell that Someone is Zimbabwean by them not telling you Is by them drinking a beer in the morning And I think Zimbabweans can agree with it See you all in Zimbabwe Thank you We finally landed in Harare Zimbabwe And I was so excited to finally touch down At the jewel of Africa By the immigration Decided to welcome us with this I want to ask African immigrants Why do you guys don't expect to see Africans Travelling within Africa There's something wrong with you guys, man Because I don't get it You don't expect to see your own people Exploring their own continent This mentality has to change See, no one sponsors my trip I'm on a journey To change the narrative And also address certain issues Like this because I am saying that It's time for me to inspire Africans To travel within their continent It's time for Africans to choose Africa As a destination instead of what Going to Europe or even Dubai To explore what they can explore in their own continent But if Africans decide to explore Their own continent and you treat them this way That's so wrong Listen, I think I have to do another video To address this issue once again Because we're tired But like I've always been saying You can't use one person's mistake To judge the entire country So we also met a nice immigration officer You want to send us somewhere down?  Jordan Those guys, I like them They play very well But I was separated in Argentina and South Africa What happened? When you miss the band now Asamuajan is so famous For missing the fans Very rich One of the richest footballers in Ghana What about Abed?  I wish him the same So it's my great grandfather Wow, my brother You made it to Ghana Exactly, from my region So we are brothers Thank you So after everything that happened I'm telling Zimbabwe to continue my plan And I know that Tony is definitely Expecting To see That you get a parcel I am the parcel myself Do you want a parcel? Do you want a parcel?  I sent you a high on Instagram Thank you, but later when I got the idea I'm like women don't keep secrets Man You figured it out This guy Oh yeah This is a guy Giving the book Wow He's a big guy now Wow Good I'm here Why is he not telling me That he's coming to Zimbabwe I knew he suspected it But I'm like let me just stick to the plan And make it happen Thank you I'm Dara I asked If you're going to come with your wife She might be busy Because I really wanted her to be around You're not busy, thank God I had to go Really? Nice The parcel is here You want to say bye bye to them?  What are you doing? I'm lying I'm lying


What's up guys Mike the Coder here. Welcome to my YouTube channel. Today we are going to go over the next coding pattern review pattern. So one of the coding interview pattern is merging intervals. And I think I made a video before back then about how to merge intervals. And that was just detecting if there's two intervals that are overlapping, right? So that was like a pretty cheat code. You could do it in one if statement. But now we're going to go over how most of these coding interviews they ask, they asked the same variation. And most of the time in these cases they ask overlapping intervals. Okay, so given n intervals where each interval denotes start time and end time, our task is to merge all the overlapping intervals and then return a list of overlapping intervals in sort of order of their start time. We're trying to merge all the intervals that are overlapping with each other. And then it should be in sort of order. Okay, an interval has like a start and an end time. So here is a overlapping interval. Let's say our input is one, four, seven, nine, three, six and eight, 10. So in our first case, we see one, four is overlapping with three, six, right? So that's overlapping between one, four and three, six. And the reason why it overlaps is because the start of the three, right, is like between one and four, right? The start of the three is between one and four. So that's why they're overlapping. Okay. And then the next overlapping that we see is seven and nine. And that's overlapping with between the interval of eight and 10, right? Because if we put them in this graph, as you can see here is seven, nine and eight and 10. They basically intersect between this time, these locations here, and they're overlapping, right? They're intersecting between each other. So in this case, what we're doing is we're trying to merge the overlapping intervals together and then return a new array of intervals. So you can see our one, four, three, six, now it becomes merged together. So the four and the three are pretty much gone. And then we have one and six now, right? One and six, that's one giant interval. And then we have another interval, which is like seven, nine and eight, 10. And those are now merged together to become seven, 10. So if we're giving the intervals one, four, three, six, seven, nine, eight, 10, right in like a giant array of it, it's going to return back one, six as an interval and then seven, 10 as another interval. They also gave us another example here. Intervals one, three, two, six, eight, 10, 15, 18. So this is another example we have where one and three is intersecting with two and six. So it be merges become one and six. And eight and 10 is just by itself, right? There's no overlapping between any of that. And then 15, 18 is just by itself, right? There's no overlapping. So we have just one giant array with one, six, eight, 10, and then 15, 18. Okay. So that's what this output is because there's no overlapping here, right? It's just one, three, two, six, and then eight, 10, 15, 18. Okay. All right. So we could go over the brute force approach. We just try all every single different type of interval possible, which is loop through one interval and go through every other interval. And then if they overlap in any form, we're just going to merge them and mark them as visited. All right. So in this case, the code here is merge intervals, right? This is in C plus plus. So they just have like an array of n intervals, right? n is equal to the size of all the intervals. And then the result is a 2d vector feature the intervals. And then here they have visited array. So they mark n as the size of the visited array. And each of these values inside of it, we're going to mark it as true or false if it's visited or not. Okay. So in this case, we're looping from zero to n. And then we're just going to check if it's not visited. So if it's visited, we're just going to continue to the next one because we don't need to check it again. Okay. So yeah, it's actually much cleaner if they wrote if the current interval is not visited, that would make more sense. But okay. But anyway, it says if if it's already visited, we're just going to continue to go to the next one. Okay. So if the current interval is already visited, we'll go to the next one. Otherwise, if it's not visited, we're going to mark it as true. And then we're going to just like set a minimum start interval as like the current interval. And then the maximum n interval as the maximum n interval. Okay, the reason why it's zero and one is because the array is an interval of always two values. But like so as you can see in intervals, it's always two values here, right? Each of these intervals are two values, one representing the start interval and the second one representing the n interval, right? So if in an array because it's indexed from zero, right, we have the start interval would be at index zero and then the n interval, the end value would be at index one. Right. So that's why in here, it's always going to be intervals at I at zero and intervals at I at one. Okay, so that's basically what our starting and our ending intervals are. All right, this is a really weird thing that they did, which was they did like a while true infinite loop. Ideally, you don't want to do this. There's better ways to do this, but I don't know why they did this. Okay. So then here, they have a count variable, CNT and they set out zero. And then what they're doing is they're going to loop through the intervals, right? And if they haven't visited yet. And if it's if the current interval is like overlapping with our minimum start and our maximum end, right, then we're going to mark it as true. And then we're just going to get our new boundaries. Right. And then we increase our count. So what this means is that like, so if we go back to the basic example up here, what we're doing is we're just going to make sure that we get the minimum start and the maximum end. So when we have one four and three, six, and we know one four intersects with three, six, the minimum start is going to be one, and the maximum end is going to be six. So when we merge them, our new interval is just going to have like the minimum start, which is one. And the ending will our new ending would be six, right? Because six is larger than four. So when we merge them together, it'll be one, six, right? So we're just trying to maintain the minimum. There's just a minimum number for our starting value. And we want the maximum ending of our ending interval. Okay. So that's what it means. So yeah, that's that. So if it's overlapping, and it's not visited, we're going to mark it as true. And then we're going to get, we're going to get our new boundaries. So this is just calling the function minimum, and it's setting the new variable. So min s is going to equal to the minimum of min s and the current starting value of our current starting value at zero, right? The current intervals j at zero. And then our max ending is going to equal to our net new max intervals ending at one. Okay, this is just going to get the boundaries. And at this point, we're going to increase by one, which is count. And yeah, so essentially what we're doing is we're just going to keep looping it until we don't have a boundary that is not visited. And then once our count is equal to zero, so we have no overlapping intervals, we just break. So yeah, this is just checking if we have no overlapping and it was never bright. Then at the end, what this is doing is it's going to push our new interval that we have, which is going to be the minimum start and the maximum end. And that's our new interval. And we're just going to push it into push it back into our result. We're going to push it back. So we're going to add our new interval with the minimum start and the maximum end and add it to end. Then at the this point, we just sort it. Okay, the Java code is literally the same thing. Exactly the same thing, actually, we kind of skip over checking if it's overlapping. So I kind of skipped over this current ending time is smaller than the minimum starting time. It's false. Okay, this is really hard. Okay, so let's say we had the interval at time five and ends at nine, and then our current interval is at like that we're currently at is that one to four? Okay, so and let's assume that in our array, the five and nine goes for the four and one and four. Okay, so like in the order would start here and then this here. Okay. So, of course, like, if you just look at the diagram, like, you know, it doesn't overlap, right? If we just look at the diagram, it definitely does not overlap at all. But our current array is like our current array has five nine before one four. Okay. So that's just like what the input is. So let's say our current array has value five nine and one four. So in this specific example, our minimum starting here would be five, right? Our minimum starting here would be five, because that's the minimum starting value. When we're just looping through it, right? And if it is greater than the current interval, ending interval. So if our current ending interval, let's say where our current ending interval is four, right? Our current ending interval is four, five is greater than our current ending interval four. So if this value of five is greater than the ending interval four, then we know it's not overlapping, right? Because the minimum starting time here, five is larger than the value of four, the ending time of four. Okay. Like this starting value of five is smaller than the current ending time of four. So because this is a case in this situation, it's not overlapping. So this returns false. Okay, so this is returns false. So that's why in this case, it returns false. But there's also another example, which is our maximum ending is smaller than the current starting time. So let's say our maximum ending is, I'd say we have interval, let's say six to 11. Okay, so let's say our current start interval start time is at six. So this is current start is at six. And then our maximum ending interval is at four. So this is a maximum and maximum end time is at four. So if this current start here is larger than the maximum ending time, we know this is also not overlapping, right? So this these values of one, four and six, 11, these are definitely not overlapping each other. And the reason why is because, well, it's just not overlapping, right? The maximum start here of six is greater than the current maximum end. So it's not overlapping. Okay, so that's that. Otherwise, it's returns true. So that means that it's definitely overlapping. Okay, so these are the two situations you could also do if you're checking overlapping. And that's a gist of the C++ code for the brute force solution. Just keep what we're doing is we're just going to keep infinitely looping through. We're going to make maintain a visited array. We have a current counter to make sure that we've counted number of overlapping intervals. We're going to loop through the array. If the if it's not visited yet, and if it's overlapping, we're going to create a new boundaries and we mark it as visited already. And then we increment number of overlapping intervals. Okay, and then if there's no more overlapping, we break and then we just add our new boundaries that we have the minimum start and the maximum end to our new array of resolutions, we sort it by the beginning by is the starting values because they want it to be like that. I don't know why they want it to be like that, but that's just what they wanted to be. And then we return result. Okay, so that's what this brute force solution is like. Okay, so in the end, we're going to have bunch of intervals that are merged. And they are not overlapping anymore. So that's a brute force solution. So let's actually go over the the optimized solution. Alright guys, so this is like the second time me recording this, because my computer kept crashing and I just had issues with it. But let's continue. Okay, so what we're going to do now is we're going to explain the optimal solution. So what is the optimal solution? Well, if you have all these intervals, right? The optimal solution is actually to sort it by the starting time. And the reason why is if you sort it by the starting time, you know where the last value of all these values end up. And it's much easier to check when it overlaps it because all the starting values are right next to each other. So let's say I give let's we go back to this top example. Okay, so we're going to go back to this top example of 1436 or yeah, actually, yeah, okay, 1436. As you can see here, the starting time of the 14, one is the starting time of one, right? And three is the starting time of three. Now, because these are sorted, right, because it's sorting by starting time, we could easily check based on the last ending time of this four, if it overlaps with the starting time of three. Okay, because they're sorted by the starting time, right, one and three, because we know the ending time of four and this interval is like between this one and three, we know it overlaps. So if we sort it by the starting time, it's much easier to check it. Whereas if it's not sorted, like, let's go over this example, right here, and say it's not sort of 1925, 1920, 1011, 1220, okay, and then there's a zero here. Well, if it's zero, if there's a zero here, and then there's a one here, and then there's a 12 here, then we don't really know if it overlaps or not. Right? It's very hard to check, right? Because then you have to like, check, Hey, is this less than this? This was on that? Like, I don't know. We don't know, right? So it's much easier if you sort it by the starting time, because once you sort it by the starting time, 00, 00, right, all the zeros of starting time are now next to each other, right? And then the ones are next to each other, and there's twos, and 10s and 12s and 19s, right? So now they're all in like a straight line. And then now because they're all like, in the starting time, sorted by starting time, we can easily just check the ending bounds of like this three doesn't overlap with one. Well, if it does overlap, then we can merge it, right? This three and overlap one is overlap with two, and so on and so forth. Then we can merge them together, right? Because we know that this starting time and the ending time, they overlap each other, right? Because we they're all sorted by the starting time. Okay, so here. Yeah, so here's how the algorithm works. We sort the intervals according to their starting time. We're going to create an array to store the merge intervals. If the current and the previous intervals do not overlap, so if they don't overlap each other, let's just add it to our merge array, right? We added to our merge array. Our merge array is our answer array, and we just add it to it. Okay, and that's it. Otherwise, so let's say they do overlap. If they do overlap, we'll merge them together and insert it into the merge array. Simple, right? If it overlaps, merge it, insert into their new array. If it doesn't overlap, let's just insert into the merge array, okay? So here's how the code works. We're given the vector of intervals. We'll sort it by the starting time, right? So in C++, if you're given like vectors of intervals or whatever pairs, and you just call sort and you pass in like the vector or interval or array, whatever it is dot begin intervals that end. What it does is it actually sorts it by whatever is the starting first, right? So if it was like a string or like an integer or anything, it's this, if you just call sort on it, it actually merges it, not merge it, actually sorts it by the starting, the starting, whatever's starting first, okay? Inside the, inside the array vector or whatever it is. So this sorts it by the starting time, right? Because we know the intervals are given by starting time and the ending time, okay? So here's what we do. We create a merged array. This merge array has a two dimensional array, okay? Two dimensional vector, two dv vector, okay? We're going to go through and loop through our intervals array. So this is our intervals array that we passed in, right? The intervals array are the ones that are that are like all messed up. It's not sorted yet. Yeah, whatever it is, right? But so what we did first, we sorted it by the starting time. So now the intervals are sorted by the starting time. And now we're looping through, okay? We're looping through our intervals, okay? Now if our merge array is empty, right? So if our answer array, this merge array is like the answer that we're returning, right? The ones that has all the values of the intervals are now merged together, right? The one that we're turning. If it's empty, that means there's nothing in the merged array, okay? If there's nothing in the merged array, that means that we're just adding the first value, right? So if we're just adding the first value, it doesn't matter if it overlaps or not, right? Because it's the first value and there's nothing who cares, right? So here, if the merger array is empty, we'll just push whatever the current interval is, right? We push whatever current interval is to our merge arrays, okay? Our merged intervals, right? So this is just adding it to the end. We're just adding it to the end of our merge array, okay? Now, here's the second one. If the merge arrays' last value at its ending time is smaller than the starting time of our current interval, right? So if the last value is smaller than the current starting time of the current interval, it does not overlap, okay? It does not overlap. So we push, we also add it to the back of our merged array. We push it back and here's why it doesn't overlap, right? So like, let's say I show you this right now real quick, okay? So let's say we have, um, let's say we have a simple interval, very easy. One to one five, okay? One five, one five, and then this interval is a 6 to 11, okay? So let's say our first interval that we have, right? We add in it, right? So this is our array. Our array has one five. So I loop it through our intervals, right? And this is the first interval I see, one five. So I add in my one five to my array, right? I add in my one five to my array. That's why I did. I add one five to my array, okay? Now, now I loop through and I go to the second interval. The second interval is 6 to 11, okay? Now what is 6 to 11? 6 to 11, 6 to 11, okay? Now, what am I checking? What am I checking here? What am I checking? If the back, the back, the last element in my merger array. So what is the last element of merger array? This interval, one five, okay? And if at the first index, so what is the first index?  If it's smaller than the current interval at the starting time. So if the current interval is 6, 6 starting time, this is the current interval, right? 6 to 11, this starting time is 6, okay? If 5 is less than 6, what do we know about this? Does not overlap. You see, right? Because this is the starting time, one five and 6 to 11. It starts at 6. 6 does not overlap for the interval of one to five, okay? This last value of five is smaller than the starting value of 6. So it doesn't overlap. If it doesn't overlap, we just add it to our new array. This new array is going to have 11, 6, 11. And then we're done, because we don't have to merge anything. It doesn't overlap. That's why. That's why, okay? So we just push it back. We push back the interval. Otherwise, let's say it overlaps. So let's say this else condition occurs and it overlaps. What happens if it overlaps? We'll see. So let's give an example when it overlaps, okay? So let's say we don't have 6, 11. Let's say that this, this is 4 or let's say the 3 to 20, okay? So in this case we just loop through the array, okay? We loop through the intervals. What do you see? The first interval we see is one five. Let's just add it to our merge interval, because we have nothing there, okay? So we add one five to our merge array, okay? Now, we check here, three twenty. Now, three twenty, right? This is, we added one five. Now we go to the next interval. Next interval is three twenty, okay? Three twenty. This is the next interval, three twenty. Now, what do we see? The last value of the merge dot back at one, is it smaller than the starting value? This five, last value, back, right? Back at one, is this five, is it smaller than the starting value of three? No, it's not, right? Five is greater than three. It's not smaller than three. Five is not smaller than three, okay? So if it's not smaller than three, we can't push this back. We cannot push interval. So what do we do? We need a merge there. So how do we merge that? Simple. We get the last value of the back of this five. And we're going to replace this five. We're going to replace the ending value of five. And how do we do that? We do merge dot back at one. Now we're going to equal it to it. Replacing this five. And what are we going to do? We're going to get the maximum of what this five is, right? The current value, which is five, and versus the ending value of our new interval. So what is our ending value of our new interval? 20, okay? 20 is our ending value of our new interval. So we're getting the max. What are we doing? We're getting the max of five and 20, okay? A max of this and this. This interval. Both of these. What is the maximum of five and 20? Simple. It's 20, okay? So this five now gets replaced with 20, okay? So now we're done, right? It's merged. These intervals are now merged, okay? One, five, three, 20 are now merged. So we have one and 20. In the end, we get 120. This is our answer. These two now are merged. And then it returns merged array. So that is how this merge code works. Sort it by the starting time. Check if it overlaps with it. If it doesn't overlap, add it to the push it back to our merge array. Then, otherwise, if it overlaps, we're going to get the last value of our merge array. We'll replace it with a new value of the max one. And we continue going forward and forward until it's done. If it's done, we push, we return merged, okay? So that's the gist of this code. I hope you guys enjoyed this part of the code. And now we're going to go over examples. How do we use this? So now I gave you the solution of this idea of merging intervals. Now how are we going to use it and apply it to different problems with different scenarios? That's how we're going to do it. Alright, let's get it started. Alright guys, we're going to go over another problem. Now how do we use this? What I just showed you and apply it to different problems. Okay. So what is this problem? What is this new problem? This time you're given an array of non-overlapping intervals. So you know these intervals do not overlap. But now we're also given a new interval. And we want to insert this new interval into our intervals array. Okay. We want to insert this new intervals in our intervals array. Okay. And we still want it to be sorted in ascending order by start. And the intervals do not have any overlapping intervals afterwards. Okay. So we want to merge them if necessary. Okay. So in this example we have one, three, six, nine. Let's actually draw it out. Okay. One, three, six, nine, and five. We'll draw this out. One, three, six, nine. So in this case we have one, three, six, nine. So let's just draw this out. Okay. We have one, three, one. Sorry guys, my thing first. One, three, and then six, nine. One, three, six, nine. Okay. And our interval that we're going to insert is two, five. This is why we're trying to insert it. So now what happens now is that they inserted it. Right. So two, five. Let's say two, five. How do I, if I draw it out. It's going to be probably between here, two, five. If we're sorting by starting interval. Right. Two, five. Somewhere around here. And now it's inserted. Right. Two, five. Now it's inserted, but you want to make sure that we have to merge when necessary. Right. Our ending arrays cannot have any overlaps. Okay. So what do they do here? They end up merging one, these two overlap. Right. This interval. One, three, and two, five overlaps. They merge them together. And this gets one, five. Okay. They have one, five. And then six, nine does not overlap. So in the end they have the new interval. One, five. Six, nine. In the new array. So in the end here it returns one, five, and six, nine. Okay. So yeah, that's how that works. Okay. We just have to insert it and make sure. So how do you do this problem? Simple. Insert it at the right spot. Merge them if necessary. Then return the new array. That's all you have to do. Okay. So let's just go over the solution here. This one is in Java. I know it's a little hard to read, but I could actually let's see. I could actually just copy and paste this into a thing and explain to you guys how this works in this in Java, but the same ALGO actually works in C++. So here, I'll actually change it to Java. I know I'll never use Java, but from here I'll do it. Okay. So I'll show you guys how to do this. What they mean by this solution. Okay. So let's explain the solution and how you apply this. So how does the solution work? Okay. So how does the solution work? Simple. So here we're creating our new, what they're doing is they're just creating a new start and a new end. Okay. This is like the new interval that they're inserting. They're inserting or a new start, a new end. Okay. And here they have an output, an output link list. You could use the link list. I don't think it really matters, honestly. What you use, but hey, in the end it's still, it doesn't really matter what you use, honestly. But yeah, you can use the link list. You can use a list. In C++ there would be a list. You use the array, whatever it is. Okay. And just make sure that in the end it's like a 2D array. Okay. So this is the output. And this is the index where it's at. And this is the, this is the index, idx and index. And this is the size of the intervals. Right. End is the size of the intervals. Okay. So here's what they do. While it's less than end and the new start is greater than the, than the current start. So what they're doing here is they're inserting, they're finding the right position where to insert. Okay. And they're inserting all the values that are before it, before the new start. Okay. That's all they're doing. So in our example here. Okay. So the old array has 1, 3 and 6, 9. Okay. And they're inserting 5, 5, 2, 5. So what they're doing is they're going to literally just loop through the whole array. So all the intervals to this one and this one and so on and so forth. And they're going to insert all the values where the new start is greater than the current beginning. So here, here, right, our new start, right, is 2. Right. What we're inserting it, or starting time for where we're inserting is 2. Right.  That's what they're doing. So they're looping through all these intervals. Okay. I'm going to loop through all the intervals. So one starting time, one starting time is less than 2. So we're going to insert that into our new array. 6 is 6 starting time less than 2. No, it's not. So we're not going to insert 6. We're not going to insert 6 to 9. We're not going to insert it. And then that's where it stops. Okay. Because currently we only have two intervals in our array. Right. But that's where it stops. But if there were more intervals, we'll continue to do that. And the reason why they're doing this, right, the reason why they're inserting all the values of the starting time is less than 2, is that this will maintain the order. It will maintain the order where you're going to insert your new interval. So your new interval 2, 5. Right. It's right here. And now what they're going to do is they're going to add it. They're going to add the interval. Okay. So here, this is just checking if there's overlap. It all puts empty Olaf's value is less than it. Right. If there's no overlap, just add it. So in this case, no overlap. Right. If there's no overlap between the starting value right, 1, 3, or 2, 5, no overlap, we'll just add it. However, in our case, it does overlap. Right. This 2 is actually between 1 and 3. The starting value 2 is between 1 and 3. So in our case, it does overlap. Right. So in this case, this if statement would be false. Right. So if it does overlap, what we're going to do, right, is here, what they do is they're going to, I don't know why they did this, but bear with me, they remove the last value of our interval. So here they actually legit just remove this, which I don't know why they did, but it doesn't matter. Right. I don't know why they did it, but hey, they could have just like gotten this last value and changed it in C plus plus. You could just get the last one and change it. But for them, they just wanted to remove it. Okay. So we removed it and that's what this code does move last. And now what we're going to do is we're going to set our new interval, the new interval that we're adding. Okay. So our new interval is going to be the maximum of the last value of our ending and the new end. So what is the last ending of our interval? Okay. My computer died again, but we'll continue it on. Okay. So what happened in the previous time? What happened in the previous time? That's a big question. So what happened previously, previously, previously, what happened previously is that we added all the intervals that did not overlap with the new start, right? That that were just before the new interval. So we added them. Okay. Now, now we're at the current interval. We want to insert it to it. And if there's no overlap, we add it to the interval. Otherwise, what we're going to do is we remove the last value. But what we also did is that here we're going to get the ending value. Okay. We're going to get the ending value. So here, what is our last value? So the last value is one three, right? One three was the last interval. Okay. So we actually removed this from the array. And then what we're doing here now is we're going to change this last value three. Right. We're going to change the last value of three. It's going to equal to the maximum of the value of three and our new end. So what is our new end? Our new end is five okay. So we're going to get the max of three and five. So what is the max of three and five? So max of three and five. That's going to equal the five. Okay. So now, this new interval, this new interval, it's its ending is gonna change to five, right, one five. And now what we're gonna do, we'll add it to our output. So now we're gonna add it to our output. So now our output is gonna have one five. So let's erase this, erase these values, our output's gonna have one five, okay? So this is gonna have one five, all right? So now that's there, we're going to, now we're gonna just, now that we merged those two values, right, we're gonna just add the rest of the intervals and merge it if necessary. So now that we have the index, right, the current index, and we'll move it to the end, we're just gonna get the current interval and just keep going, right, keep going from the end. We have a start in the end now, so now our current to the ending, right, we're gonna go on this interval now, six nine, because that's our next interval, six nine. And now what we're gonna do is, if it overlaps, if it overlaps, we're gonna merge it to our ending. There's no overlap, we'll just add it here. There's no overlap, six nine does not overlap with one five, so we're just gonna add it, six nine, okay? And then we're done, that's it, we're done. And then we just return this array. So how does the overlap work? Same thing, if there is no overlap, just add an interval. So here we get the last value ending of our last value and if it's less than the start, so the ending of the last value, remember this last value of five, right? If it's less than the start, so the start is six, or at the current interval, or the current interval, six, if it's less than that, we'll just add it, okay? It means there's no overlap when we add it. Otherwise, we do the same thing, remove the last value in our array. We re-add the new value, we re-get our new interval, you get the maximum of the endings, and then we re-add it into our interval. And at the end, here what they do is they convert the link list into a new array. So if you did a link list, you just convert it to a new array like this. Otherwise, it's just like that, okay? You just return your array. So yeah, that's just how to do this problem. And let's continue to the next problem, all right? Okay, we're going over another problem. Meeting rooms, too. Given an array of time intervals, intervals where the I, intervals of I equals the start of I and the end of I, this time we're gonna return the minimal number of conference room needed, okay? So if we have a meeting at a starting time and ending time, right? And we have that at a conference room, then we can't have other people inside that conference room, right? We only can have a meeting where it starts and end and there's one conference room at a time per person. Okay, so if there's like a meeting like this, right? The number of conference rooms it would take would be two, right? Because you need two conference rooms to actually do this meeting. You need two conference rooms for this one, right? For these two meetings that will last and then you need another one for this one, zero, 30, because those, that's another person needs to be in that conference room, right? In order to require to have all these meetings, okay? Like if I have started at five and I go to 10, right? Then the conference room is empty so I could go 15 to 20, okay? So that's one conference room required for this. Whereas for this one, zero to 30, I can't really have another, I can't really use the same conference room as the ones, as the guys in these, right? Because zero to 30 will interfere with the meetings between these. So I need another conference room, right? So I would have two conference rooms. So that's why the answer output is two here. And now here in this case, seven, 10, two, four, right? We have two four as one meeting. It starts at a time two and ends at a time four. But we have enough time to start our next meeting of seven to 10, right? We have two four and we have one conference room, right? For two four, right? The guys will leave after two four. So then another guy can come into the conference room and it's not occupied for seven and 10. So then we could just have one conference room and the guy would come in at two, leave at four and come in at seven and leave at 10. So then that's why we have one conference room for this one, okay? So how do you do this problem? This problem is a little more trickier. It's way trickier, but it's okay, all right? This time we need to, because of each conference room is different, right? This time is different. We can't just like merge them together because the intervals need to be there. So what we're doing now is we're gonna actually create two arrays, new arrays, splitting all the intervals between the start time and the end time, okay? And the reason why if we do this, is because now we have all the values of the start and the end time of the start interval and end interval and then we're gonna sort them. We're gonna sort both the start and end time, okay? So now there's just a bunch of numbers for the start time they're all sorted and the end time they're all sorted, okay? Now we're gonna loop through the starting interval and then each time we loop through the starting interval, right? If it's less than the ending pointer, going through the ending pointer, we're gonna increment the ending pointer by one, okay? Otherwise we're gonna increment rooms by one, okay? Because the reason why is because we need to, at this point, now that they're all are sorted, right? Now they're all sorted. We're just having pointers at both of these ends and going through the starting and the ending interval, anytime we have a time where the start time is less than the end time, we're gonna increase the number of rooms needed, okay? Because anytime we have an occupied start, we have rooms and then at any time we don't need, then they're unoccupied, so then if they do interfere with the ending time, our current ending time, we have to increment the number of rooms because anytime there's interference, we need to increment the number of rooms, okay? And yet the end we return rooms. Okay, so that's the solution for this one. And I think other, yeah, so basically we don't really care about the actual specific intervals because we just need to know that if there's possible to do an allocation because we need to know when a room gets freed up. So it really doesn't matter like what, it doesn't matter if we need to merge them or not, okay? We just have to go through, make sure the starting times and the ending time moving through them, any time it's smaller than it, then we need to add one by a room and then we're going to the next one, okay? So yeah, that's how you do this problem. I hope you guys enjoyed this video. This video took away too long to make. I just kept crashing. Rate, cop, subscribe. I'll check you guys later. Peace.


So, we now come to our first keynote speaker, Professor Daron Acemolu, who will discuss the topic, Can We Have a Better Future for Work, Wages and Democracy? Mr. Acemolu is a professor at the Massachusetts Institute of Technology and he has authored various books on related topics and received a number of awards for his work. Viewers can read more details about our speakers on the ESRB website under the conference speakers. And now, Professor Acemolu, the floor is yours. Thank you very much. It's a true pleasure to talk to the European systemic risk board about a set of issues that I think many of you have thought about a little bit, but I believe they need to be more of the focus of questions about systemic risk and that's about the effects of new digital technologies, especially artificial intelligence on broader society. There is an incredible amount of excitement about AI and there is no doubt that there have been huge advances both in applied and theoretical research in AI and the fruits of these are visible from the fact that AI is now permeating many different parts of the economy, the financial system, communication, entertainment, health and other areas. There's a huge amount of optimism as well. For example, the Economist magazine wrote recently that fears of job losses from AI are completely exaggerated and we might get fewer checkout attendants at supermarkets but more massage therapists are nothing to worry about and productivity growth is going to make all of us the beneficiaries of these new technologies. McKinsey Davos statement for 2022 was in the same vein arguing that we're going to create a transform manufacturing sector, help build fulfilling, rewarding and sustainable careers thanks to AI and there are of course a huge amount of potential from AI technologies in risk regulation, financial transactions, health and many other areas. But when you look at the way that many industrialized economies are working today, there are also clear reasons for concern. Even well before the pandemic and before the rapid spread of AI, not all was well. In many advanced nations, for example here I'm showing the data for the US, the labor share has plummeted. So much more of the income in the economy is now going to capital than labor. Again, focusing in the US, this is not just a story of capital versus labor. There has been a systemic increase in inequality within labor groups and in a way that looks very jarring. Here in this picture I'm showing the evolution of real wages for 10 demographic groups in the United States. All the way from high school dropouts to workers with postgraduate degrees, men and women. And what you see is that in the 1960s and 70s, and the same was true even more in the 1950s from different data sets, you see a period of shared prosperity where the real wages of all 10 demographic groups were growing in tandem about 2.5% in real terms. And then from around 1980 onwards, you see a complete reversal, a much larger increase in inequality, but even more remarkably, a decline in the real wages of low education groups. For example, high school graduate, high school dropout men, same thing for women. Now across the industrialized nations, this is a fairly unique picture. No other country has as weak labor market regulations protecting low wage workers as the United States, but the overall trend towards inequality both at the top and in the middle of the distribution and stagnant wages at the bottom are fairly common. So if you look at the omnibus measure of inequality, the Gini coefficient, US is ahead of other countries, leader in inequality and has had a very large increase in inequality since the early 1980s, but the same as more or less the case for other industrialized nations. Another very important parallel across these countries is that the employment structure has evolved in a very similar way. Again, as the Economist magazine and McKinsey Davos pointed out, this may or may not be a cause for concern. Perhaps some jobs are going to disappear, new jobs are going to come, but the extent to which the employment structure has changed is quite remarkable. So if you look at all countries in the industrialized world for which we have data and you look at the employment structure by occupation, separating occupations into lowest paying group, you know, the very unskilled service work, homework, protection, etc. Highest skill work, professional jobs, managerial jobs, technicians, engineers in green and the middle paying ones, clerical work, production work on factory floors in red, what you see that these middle paying occupations, the middle class has contracted in all nations, not just the United States. These are all sort of pre AI developments and my own work has emphasized that they are intimately linked to automation trends. And in particular, for example, both digital automation in offices and robot based automation in factories. And another slide I was going to share shows, for example, across the United States, what happens to employment and manufacturing employment in local labor markets, commuting zones where you have more intensive adoption of robots. And you see a decline in both employment and wages. It's emblematic of the heartland of heavy industry in the United States like the Midwest, but it's throughout the economy. So what this chart shows is the contribution of pre AI automation on to inequality by looking at the real wage changes for detailed demographic groups distinguished by education, gender, age and ethnicity. And on the horizontal axis, looking at whether the tasks that they used to perform in 1980 have been automated. So for example, a number of 25 or 30% shows that for that demographic group, many of the tasks in which they used to specialize have been automated. On the left hand side, you see that before the wave of automation, there wasn't much of a relationship between what was happening before the 1980s and this post 1980 automation. But on the right, you see a very sharp negative relationship indicating that much of that inequality that I depicted in the first few slides in the US is related to automation. So this is again, mostly before AI. It's taking place with more basic digital technologies and offices. But it is a worrying pattern, especially for any type of shared prosperity. And it brings all of the risks that high levels of unemployment do. So how levels of inequality and high levels of opportunity do. Now the question is, what is AI going to do in this picture? And really, can we see the footprints of AI in the labor market already? So in the next slide, what I show is that if you look at various measures of AI and here I'm focusing on AI related job postings in the United States, you see there's very little of it in the 2007, 2010, 2011, and so on. But around 2015, there is a huge pickup in AI activity. And it's exactly like AI proponents are arguing. It's quite widespread across industries. You see it pretty much in every industry, broad industry. Now the question is, what is AI going to do? How is it going to reorganize jobs? Is it going to create opportunities and so on? So in the next slide, I talk briefly about this because one promise of AI is that in fact it could create new human tasks, complementing workers, facilitating trade and matchmaking, reorganizing production. And in fact, there were many early pioneers of digital technologies such as MIT's Norbert Wiener, Douglas Engelbar, JCR Licklider, who advocated this type of perspective, thinking that the biggest use of machines would be to increase human capabilities. And there were significant advances in this direction, including the mouse and hypertext, which Engelbar introduced in this effort and many others. But if you look at the recent past, much of AI activity within the economy has focused on automation and data collection. On the automation side, one way of seeing that is in the next slide, and you could look at which are the companies that are adopting, which are the workplaces, establishments that are adopting AI technologies. And what these three charts do is that they divide US establishments into four quartiles. The blue and the green are the ones that have a lot of tasks that can be automated by AI. And the red and the yellow don't have many and uses three different measures of how which tasks can be automated. And what you see is that the bulk of the increase in AI comes from businesses that seem to want to automate things. And in fact, in the next picture, you see that those same businesses, again shown in green and blue, slow down their hiring. In fact, they stop hiring more workers from 2015, whereas the non-AI affected yet yellow and black continue to increase. This is true in a much more detailed granular level, but I'm showing it at this broad brush for making the presentation simpler. So where does this leave us? Well, I think what it leaves us is with a question of whether we are using AI for continuing a trend that had started earlier and excessively automating. And there are reasons why for worrying about excessive automation, because if you look at the direction of AI, it's very heavily influenced by the priorities of a handful of companies. According to McKinsey, two-thirds of all spending on AI comes from a handful of US and Chinese companies. Many companies are excessively focused on cost cutting. And there are also other factors. Let me sort of mention two of them. The tax code in most of the industrialized nations today powerfully supports capital, but not labor. So here I'm showing the data for the US. If you look at the marginal tax rate that a worker and a firm would pay, it's about 25 percent and it's remained at 25 percent for over 40 years. But if you look at the tax that a company would pay for installing capital to replace workers, that used to be around 15, 20 percent, but it's now less than 5 percent. So there are quite significant financial inducements to companies to invest in machines instead of workers. And then to add to it, and I think the whole field of AI has gone in a direction where things like reaching human parity, performing human tasks, becoming more human-like are the most valued and prized achievements. So that provides another impetus for going more in an automation direction. So if we go to the next slide, what this picture shows is one little piece of addition to that narrative by emphasizing the role of cost cutting. And cost cutting has become a major concern for many corporations in the United States and in Europe. And in recent work, for example, my co-authors Alexi and Daniel Le Maire, we look at what happens in Denmark and the United States when CEOs that are trained in business education like an MBA degree take the helm at a company. And what we find is that in both countries, one of the major things, actually the most important thing that they do is they slow down wage growth and they reduce the labor share. And a lot of that we trace to the sort of the priorities that these new managers are bringing to the job, making the corporation leaner, re-engineering the corporation, looking after the shareholder interests and so on. So there is sort of a synergy here between the tools that are made available by digital technologies, including AI and what the companies are or what the new managers are envisaging as the most interesting direction. So if you go back, if you go to more slides, this is showing that they're not much more productive, actually, it's just a wage reduction. But what I want to sort of emphasize next is actually the risks are not just in the financial domain and in the job domain, but also in the democracy domain. Growing inequality has coincided around the world with the retrenchment of democracy. And then from the late 1970s to around 2016, every year there was improvements in democracy around the world. More countries were becoming democratic and existing democratic countries were improving their democratic quality. But around 2016, we see a reversal in this. And from then on, more and more countries are abandoning democratic institutions or clamping down on political rights and freedom of speech and so on. Now, in the next slide, I discuss what the reasons for that might be. And there are obviously direct and indirect reasons. Growing economic disparities have become a major lightning rod. But also there is growing evidence that how we are using AI is damaging democracy. One aspect is from the government side, AI-powered surveillance technologies in the hands of non-democratic governments is creating major pressures on AI around the world. But also in the industrialized world, you know, the ad-based business models are transforming many of the platforms that more and more people are using. And the structure of these platforms is creating both the wrong types of incentives for democratic discourse and the wrong type of engagement from bottom-up sort of processes, which are, of course, critically important for democratic continuity. Now, there are additional things. Again, I bring it back to the AI researchers and what the ethical responsibilities of AI researchers are. But let me not get into that. Let me sort of make two more points, and then I will conclude. If we go to the next slide, what I show is that actually, or what I start arguing is that we shouldn't actually fear AI. It really depends. New technologies are things that give us additional tools. They expand our capabilities, and it's how we use them that's critical. And that's why regulation here is absolutely important. If we regulate them right and if society directs them in more socially beneficial direction, it becomes a very powerful tool in our hands to improve our objectives, creating shared prosperity, less greater stability, less unemployment, less inequality. And in fact, there are great examples of how this was done during the last several decades. If we look at Germany, Japan and South Korea, we see that the robots have had very different effects than they had in the United States. Why? Well, the next picture shows a very important part of that. Actually, sorry, skip them to the next one. I'm not gonna talk about this given that time is short. What you see is that countries like this, South Korea and Germany have aged very rapidly. But as they aged and they started facing labor shortages, at the same time, they also hugely increased their investments in robots. So on the left, you see in green and gray, the very large increase in aging, the fraction of the population that's above 55 in South Korea and Germany. And on the right, you see these two countries, again, in green and gray, much ahead of others in terms of investments in robots. And the consequence of this has been that actually productivity has increased. They have been able to deal with labor shortages and in fact have increased their exports in the sectors which rely on these robotics production. So let me now conclude, which is I'm gonna skip the next slide, which shows the same pattern for many more countries, but let me conclude with the final slide. So future of work, future of democracy, I think I cannot imagine more important topics and I think today we cannot talk of the future of work and future of democracy without mentioning the word risk. And I think AI is necessarily going to have a major impact on these things. But how it will impact these and other outcomes is not predetermined. For example, we can have AI for good automation, high productivity automation technologies accompanied by new tasks, new opportunities for workers, or we can have bad automation, reducing employment, increasing inequality, as I've shown from a few countries has been the case. We can have good communication technologies, which was the hope in the 1990s when digital technologies were first spreading, creating new public spheres, foundations for more decentralized action, greater democratic responsibility, or we can have bad communication technologies facilitating surveillance, misinformation, emotional outrage, and polarization. And I think regulatory responsibility, researchers' responsibility, especially in the AI field, and also society's responsibility, bottom-up participation in the direction of these technologies are gonna be the crucial factors determining this future. Thank you. Thank you very much, Professor Ate Morlu. So we have a few questions for you before we let you go. And the first question is, you pointed out very well, obviously, the benefits and the challenges of AI. Now, how can we ensure that investments into AI and technological progress are put to good use for the economy? That's the million dollar question. And unfortunately, I'm gonna let you down. I don't have a perfect answer to that. If I only did, I think every technology is different. In some cases, naturally they're going to be some players, researchers, companies that are going to push in different directions. I think in the case of AI, we got off to a bad start. And the bad start is because AI is already under the control of the largest corporations that humanity has ever witnessed. And these corporations have very specific business models. So we're not getting the sort of diversity that would be the foundation for many different interesting users. So what that means is that we need two sorts of countervailing forces to create a playing field in which different types of applications of AI can be experimented with. And those that have social benefits can be sort of pursued more.  We need to regulate how, for example, online platforms work. And also we need societal pressure. So the democratic process, even if it's impaired right now, as I've mentioned, needs to work in order to sort of provide input from society how we want these AI technologies to be used. We want them to be used for ceaseless data collection for more discrimination, for less choice for individuals or for other things. I think that there is, regulators are going to have an important stay in this, but it's not just regulators business. I think it's a more bottom-up process that we need. Thank you very much for your answer. Another question we have here is on income inequality. And you spoke quite a bit about that already. What are the implications of higher income inequality and financial stability? I think that's another great question. I mean, obviously in industrialized countries, we are going to have some amount of inequality and we need some amount of inequality. If we were trying to get everybody to have the same income, that wouldn't be good for entrepreneurship. It wouldn't be good for investment. It would not generate incentives for people to get into different sort of fields in order to sort of be more ambitious. But we have way past those levels of inequality. For example, again, the US is an extreme case, but US was already a fairly unequal economy in 1980. And almost every year, inequality has increased since 1980. And today there is a huge gulf between people in the top 1%, for example, and those at the bottom. So those sorts of levels of inequality, I think create economic, social, and risk problems. Economically, I think they imply that economic opportunities are not going to be open to everybody. Those who have much more money are going to be able to monopolize the best education, the best jobs, the best social network. Socially, it's going to create a lot of this content. I don't think you can understand what's going on with, for example, the populist challenge, especially from the right in many industrialized nations, without taking this huge increase in inequality into account. And that's probably as big a risk as any financial crisis. But also financially, I think inequality creates more risk-taking, more irresponsible behavior because people are trying to sort of make up for what they cannot do through economic opportunities. So I don't think it is a coincidence that people are after get rich quick schemes such as crypto in a time where economic opportunities have dwindled. So I think we need a more holistic approach and financial risk and general risk assessment has to be a central part of that. Thank you very much. And one last question on that. I mean, one step further, AI can impact financial stability. So how will the markets change when more financial decisions are made by AI rather than human resources? Well, I think that's another fantastic issue. I mean, I think, for instance, AI has the capacity to help regulation greatly. One of the issues of regulation is that regulators don't know many of the aspects of risks that are brewing and hidden in balance sheets. They cannot, in real time, keep up with new products, new risk-taking opportunities. The shadow banking, for example, that remained for a long time unregulated was partly as a result of that. So AI tools can be hugely useful in the hands of regulators when they are used correctly. But at the same time, we also know that as more machine-based investment takes over, that's going to introduce new risks as well. In an ideal world, you can say, well, machines are gonna invest better than humans, and they're gonna avoid some of the human-created risks. I don't think there's any evidence of that as yet, and I don't think that's gonna be the case in the near future. So we need to have a new sort of regulatory framework. How do you regulate the machines that do the investment as well? All right, thank you very much. I mean, we will let you go at this point, but thank you very much for your time.