Jun. 17, 2024
Hit Dice:
d8 per Artificer level
For more Casting Baginformation, please contact us. We will provide professional answers.
Hit Points at first Level:
8 + your Constitution Modifier
Hit Points at Higher Levels:
1d8 (or 5) + your Constitution modifier per artificer level after 1st
Saving Throws:
Constitution, Intelligence
Skills:
Choose two from Arcana, History, Investigation, Medicine, Nature, Perception, Psionics, or Sleight of Hand.
Masters of unlocking magic in everyday objects, artificers are supreme inventors. They see magic as a complex system waiting to be decoded and controlled. Artificers use tools to channel arcane power, crafting magical objects. To cast a spell, an artificer could use alchemists supplies to create a potent elixir, calligraphers supplies to inscribe a sigil of power on an allys armor, or tinkers tools to craft a temporary charm. The magic of artificers is tied to their tools and their talents.
The object sheds bright light in a 5-foot radius and dim light for an additional 5 feet.
The chosen property lasts indefinitely. As an action, you can touch the object and end the property early. You can bestow magic on multiple objects, touching one object each time you use this feature, though a single object can only bear one property at a time. The maximum number of objects you can affect with this feature at one time is equal to your Intelligence modifier (minimum of one object). If you try to exceed your maximum, the oldest property immediately ends, and then the new property applies.
Cure Wounds
, you can cast it using a 1st-level or a 2nd-level slot. Casting the spell doesnt remove it from your list of prepared spells. You can change your list of prepared spells when you finish a long rest. Preparing a new list of
Spell Save DC = 8 + your Proficiency Bonus + your Intelligence modifier
At 1st level, you learn how to invest a spark of magic into mundane objects. To use this ability, you must have tinkers tools or other artisans tools in hand. You then touch a Tiny non-magical object as an action and give it one of the following magical properties of your choice: The object sheds bright light in a 5-foot radius and dim light for an additional 5 feet. Whenever tapped by a creature, the object emits a recorded message that can be heard up to 10 feet away. You utter the message when you bestow this property on the object, and the recording can be no more than 6 seconds long. The object continuously emits your choice of an odor or a nonverbal sound (wind, waves, chirping, or the like). The chosen phenomenon is perceivable up to 10 feet away. A static visual effect appears on one of the objects surfaces. This effect can be a picture, up to 25 words of text, lines and shapes, or a mixture of these elements, as you like.The chosen property lasts indefinitely. As an action, you can touch the object and end the property early. You can bestow magic on multiple objects, touching one object each time you use this feature, though a single object can only bear one property at a time. The maximum number of objects you can affect with this feature at one time is equal to your Intelligence modifier (minimum of one object). If you try to exceed your maximum, the oldest property immediately ends, and then the new property applies.You have studied the workings of magic and how to channel it through objects. As a result, you have gained the ability to cast spells. To observers, you dont appear to be casting spells in a conventional way; you look as if youre producing wonders using mundane items or outlandish inventions.You produce your artificer spell effects through your Tools. You must be proficient with the Tool to use it in this way. After you gain the Infuse Item feature at 2nd level, you can also use any item bearing one of your infusions as a spellcasting focus.At 1st level, you know two cantrips of your choice from the Artificer Spell List . At higher levels, you learn additional artificer cantrips of your choice, as shown in the Cantrips Known column of the Artificer table. When you gain a level in this class, you can replace one of the artificer cantrips you know with another cantrip from the artificer spell list.The Artificer table shows how many spell slots you have to cast your Artificer Spells . To cast one of your Artificer Spells of 1st level or higher, you must expend a slot of the spells level or higher. You regain all expended spell slots when you finish a long rest. You prepare the list of Artificer Spells that are available for you to cast, choosing from the Artificer Spells List . When you do so, choose a number of Artificer Spells equal to your Intelligence modifier + half your artificer level, rounded down (minimum of one spell). The spells must be of a level for which you have spell slots. For example, if you are a 5th-level artificer, you have four 1st-level and two 2nd-level spell slots. With an Intelligence of 14, your list of prepared spells can include four spells of 1st or 2nd level, in any combination. If you prepare the 1st-level spell, you can cast it using a 1st-level or a 2nd-level slot. Casting the spell doesnt remove it from your list of prepared spells. You can change your list of prepared spells when you finish a long rest. Preparing a new list of Artificer Spells requires time spent tinkering with your spellcasting focuses: at least 1 minute per spell level for each spell on your list.Intelligence is your spellcasting ability for your Artificer Spells ; your understanding of the theory behind magic allows you to wield these spells with superior skill. You use your Intelligence whenever an Artificer Spell refers to your spellcasting ability. In addition, you use your Intelligence modifier when setting the saving throw DC for an artificer spell you cast and when making an attack roll with one.= 8 + your Proficiency Bonus + your Intelligence modifier= your Proficiency Bonus + your Intelligence modifierYou spend 10 minutes to prepare yourself to examine the pure magical energy of the Weave. For the next ten minutes after your preparations you can sense the faint aura of magic around visible objects within 30 feet of you. The aura tells you the spells school of magic and any noticeable source of magical energy. This ability can penetrate thin barriers, but it is blocked by 1 foot of stone, 1 inch of common metal, a thin sheet of lead, or 3 feet of wood or dirt. Alternatively you can spend 10 minutes to learn the properties of a magical item and how to use them, whether it requires attunement to use, and how many charges it has, if any. You learn whether any spells are affecting the item and what they are. If the item was created by a spell, you learn which spell created it. At 11th level, you can use both of these benefits using an action instead of 10 minutes.You can cast an Artificer Spell as a ritual if that spell has the ritual tag and you have the spell prepared.You can replace a cantrip you know with another cantrip available to you on a long rest.When you select this class you choose the type of specialist you are (Options are at the bottom of the page). Your choice grants you features at 3rd level, 5th level, 9th and 15th level.At 2nd level, you gain the ability to imbue items with certain magical infusions. The magic items you create with this feature are effectively prototypes of permanent items.When you gain this feature, pick four Artificer Infusions to learn, you learn additional Infusions of your choice when you reach certain levels in this class, as shown in the Infusions Known column of the Artificer table. Whenever you gain a level in this class, you can replace one of the Artificer Infusions you learned with a new one.Whenever you finish a short rest, you can touch a object and imbue it with one of your Artificer Infusions , turning it into a magic item. An Infusion works on only certain kinds of objects, as specified in the infusions description. If the item requires attunement, you can attune yourself to it the instant you infuse the item. If you decide to attune to the item later, you must do so using the normal process for attunement (spending an hour or during a Short Rest). Your Infusion remains in an item indefinitely, but when you die, the Infusion vanishes after a number of days have passed equal to your Intelligence modifier (minimum of 1 day). The infusion also vanishes if you give up your knowledge of the infusion for another one. You can infuse more than one nonmagical object at the end of a short rest; the maximum number of objects appears in the Infused Items column of the Artificer table. You must touch each of the objects, and each of your infusions can be in only one object at a time. Moreover, no object can bear more than one of your infusions at a time. If you try to exceed your maximum number of infusions, the oldest infusion immediately ends, and then the new infusion applies.At 3rd level, you learn how to produce exactly the tool you need: with tinkers tools in hand, you can magically create one set of artisans tools in an unoccupied space within 5 feet of you. This creation requires 1 hour of uninterrupted work, which can coincide with a short or long rest. Though the product of magic, the tools are nonmagical, and they vanish when you use this feature again.When you reach 4th Level, and again at 8th, 12th, 16th, and 19th level, you can increase one ability score of your choice by 2, or you can increase two Ability Scores of your choice by 1. As normal, you cant increase an ability score above 20 using this feature. Alternatively you can take a Feat from the Feats List Starting at 6th level, your proficiency bonus is doubled for any ability check you make that uses your proficiency with a tool.Starting at 7th level, you gain the ability to come up with solutions under pressure. When you or another creature you can see within 30 feet of you makes an ability check or a saving throw, you can use your reaction to add your Intelligence modifier to the roll. You can use this feature a number of times equal to your Intelligence modifier (minimum of once). You regain all expended uses when you finish a long rest.When you reach 10th level, you achieve a profound understanding of how to use and make magic items: You can attune to up to four magic items at once. If you craft a magic item with a rarity of common or uncommon, it takes you a quarter of the normal time, and it costs you half as much of the usual gold.At 11th level, you learn how to store a spell in an object. Whenever you finish a long rest, you can touch one simple or martial weapon or one item that you can use as a spellcasting focus, and you store a spell in it, choosing a 1st- or 2nd-level spell from the Artificer Spell List that requires 1 action to cast (you neednt have it prepared). While holding the object, a creature can take an action to produce the spells effect from it, using your spellcasting ability modifier. If the spell requires concentration, the creature must concentrate. The spell stays in the object until its been used a number of times equal to twice your Intelligence modifier (minimum of twice) or until you use this feature again to store a spell in an object.At 14th level, your skill with magic items deepens more: You can attune to up to five magic items at once. You ignore all class, race, spell, and level requirements on attuning to or using a magic item.Starting at 18th level, you can attune to up to six magic items at once, and you can craft magic items up to Rare quality.At 20th level, you develop a mystical connection to your magic items, which you can draw on for protection: You gain a +1 bonus to all saving throws per magic item you are currently attuned to. If youre reduced to 0 hit points but not killed outright, you can use your reaction to end one of your Artificer Infusions , causing you to drop to 1 hit point instead of 0.
One of the highest staring gold amounts, the artificer has some of the most expensive gear outside of Heavy Armour, usually having to balance several crafting choices as well as magical item creation.
One of the highest staring gold amounts, the artificer has some of the most expensive gear outside of Heavy Armour, usually having to balance several crafting choices as well as magical item creation.
Travelling Doctor Build
Lesser Restoration
without expending a spell slot and without preparing the spell, provided you use alchemists supplies as the spellcasting focus. You can do so a number of times equal to your Intelligence modifier (minimum of once), and you regain all expended uses when you finish a long rest.
Greater Restoration
andHeal
without expending a spell slot, without preparing the spell, and without material components, provided you use alchemists supplies as the spellcasting focus. Once you cast either spell with this feature, you cant cast that spell with it again until you finish a long rest.
Librarian Build
Bane
andBless
spells are Artificer spells for you, and you add them to your spellbook. You cvan cast both of these spells at a level equal to your proficiency bonus, a number of times equal to your Intelligence modifier (minimum of 1), and you regain all expended uses when you finish a long rest.
Protection from Evil and Good
at a level equal to your proficiency bonus, and a number of times equal to your Intelligence modifier (minimum of 1). You regain all expended uses of this ability after a long rest.
Travelling Blacksmith Build
Gunnery Pirate Build
Mending
spell is cast on it, it regains 2d6 hit points. It disappears if it is reduced to 0 hit points or after 1 hour. You can dismiss it early as an action. When you create the cannon, you determine its appearance and whether it has legs. You also decide which type it is, choosing from the options on the Eldritch Cannons table. On each of your turns, you can take a bonus action to cause the cannon to activate if you are within 60 feet of it. As part of the same bonus action, you can direct the cannon to walk or climb up to 15 feet to an unoccupied space, provided it has legs.Eldritch Cannons
Underdark Guardian Build
Steel Defender (medium/large) AC: 15 HP: 2 + your Intelligence modifier +5 times your artificer level Speed: 40ft Senses: Darkvision 60ft
You determine the creatures appearance and whether it has two legs or four; your choice has no effect on its game statistics. If the
Mending
spell is cast on it, it regains 2d6 hit points. If it has died within the last hour, you can use your smiths tools as an action to revive it, provided you are within 5 feet of it and you expend a spell slot of 1st level or higher. The steel defender returns to life after 1 minute with all its hit points restored. At the end of a long rest, you can create a new steel defender if you have your smiths tools with you. If you already have a steel defender from this feature, the first one immediately perishes.
Crazy Inventor Build
Teleport
orPlane Shift
without having the spell prepared. You regain this ability on a long rest.
Marionetter Build
If you are looking for more details, kindly visit Purchase Fiberglass Filtration Mesh.
Related links:Frostbite
, you can choose for the effigy connection to deal cold damage, regardless of whether you exposed the effigy to the actual spell effects or not.
Dominate Monster
on a stringed creature once without expending a spell slot. Once you have used this feature, you cannot use it again until you finish a long rest.
Forest Trapper Build
Mould Earth
cantrip.
Hunter's Mark
. When you cas the spell, you have advantage on Lore checks about your marked target and learn vulnerabilities and saving throws. You can cast the spell at 1st level a number of times equal to your proficiency bonus without using a spell slot. You regain all expended uses of this feature on a long rest.
Mending
spell is cast on it, it regains 2d6 hit points. It disappears if it is reduced to 0 hit points or after 1 hour. You can dismiss it early as an action. Once you create the barricade, you cant do so again until you finish a long rest or until you expend a spell slot of 1st level or higher. You can only have one barricade at a time and cant create one while your barricade is present. When you create cover, your allies gain the following additional effects below:
An Alchemist is an expert at combining reagents to produce mystical effects, by far the most far-flunk of Artificers. The heartland of this particular craft is in Halruaa, Chult, and the Trade Lanes of the Serpent Isles, where powerful and reactive reagents and arcane plant life grow in abundance. These craftsmen can often settle down with impunity, many townships lacking Doctors or the various Church-run scams throwing resources and support behind a good Alchemist.Arcanist Robes [Alchemist] (1gp)Dagger (1d4 piercing, range 20/60ft, Finesse, Light): 1lb, 2gpLight Crossbow (1d8 piercing, range 80/320ft, Ammunition, Loading, Two-Handed): 5lb, 25gpHealers Kit (4gp), Herbalist Pouch (10gp) and Alchemists Station (50gp)Scholars Pack (14gp) containing a backpack, a notebook, ink & pen, parchment, a little bag of sand, and a sealing wax.When you adopt this specialization you gain proficiency with Alchemy and Herbalism . You can also use and administer Alchemy Potions or Herbalism Tinctures as a bonus action. You can use a divine spell foci as a focus for your artifcier spells.You always have certain spells prepared after you reach particular levels in this class, as shown at the bottom of the Artificer Spell List . These spells count as Artificer Spells for you, but they dont count against the number of Artificer Spells you prepare.Beginning at 3rd level, you have become a master of mixing reactive solutions to create unique Elixirs . You can administer elixirs to others or yourself as a bonus action. These Elixirs can be added to Alchemy Potions Herbalism Tinctures , and Poisons to pair with the affect. You learn a number of Elixirs equal to your Intelligence modifier +1 (minimum of 2). At the end of a long rest, you create a number of Elixirs equal to double your proficiency modifier. You can use an action to refill an expended Elixir by expending a spell slot of 1st level or higher for each one.At 5th level, you develop masterful command of magical chemicals, enhancing the healing and damage you create through them. Whenever you cast a spell using your alchemists supplies as the spellcasting focus or an alchemy attack, you gain a bonus to one roll of the spell. That roll must restore hit points or be a damage roll that deals acid, fire, necrotic, or poison damage, and the bonus equals your Intelligence modifier (minimum of +1). This increases to 1d8 + your Intelligence modifier at 9th level, and 2d8 + your Intelligence modifier at 15th level. You also gain the following additional elixir affects;Starting at 9th level, you can incorporate restorative reagents into some of your works: Whenever a creature drinks an experimental elixir or healing tincture you created, the creature gains temporary hit points equal to 2d6 + your Intelligence modifier (minimum of 1 temporary hit point). You can castwithout expending a spell slot and without preparing the spell, provided you use alchemists supplies as the spellcasting focus. You can do so a number of times equal to your Intelligence modifier (minimum of once), and you regain all expended uses when you finish a long rest.You also gain the following additional elixir affects;By 15th level, you have been exposed to so many chemicals that they pose little risk to you, and you can use them to quickly end certain ailments: You gain resistance to acid damage and fire damage, and you are immune to poison. You can castandwithout expending a spell slot, without preparing the spell, and without material components, provided you use alchemists supplies as the spellcasting focus. Once you cast either spell with this feature, you cant cast that spell with it again until you finish a long rest.What are the best ways to store vast amounts of information? That question has occupied chroniclers and librarians for centuries. Scrolls and books were the finest information-storing methods for a long time, but the first Archivists imagined something greater: using that magic to improve the world around them. Storing is not enough, but making it available to the world. These techniques have yet to be perfected and institutionalized, and of all artificers, archivists are on the cutting edge of arcane science.Studded Leather (12 + Dex mod AC): 13lb, 45gpStaff (1d6/d8 bludgeoning): 4lb, 2spSimple Flintlock (2d10 force, range 10/40ft, Loading): 5lb, 12gpSpell Prism (120gp), Calligaphers Kit (1gp)Scholars Pack (14gp) containing a backpack, a notebook, ink & pen, parchment, a little bag of sand, and a sealing wax.When you adopt this specialization you gain proficiency with Astrology and Scribing . Also, when Scribing Spell Scrolls it takes you a quarter of the normal time, and it costs you half as much of the usual gold. You can also use arcane spell foci as your artificer spell focus.You always have certain spells prepared after you reach particular levels in this class, as shown at the bottom of the Artificer Spell List . These spells count as Artificer Spells for you, but they dont count against the number of Artificer Spells you prepare.You became proficient in the ways of Wizard Spellcrafting , even without an innate talent. You gain your own Spellbook, where you can transcribe both Wizard Scrolls and create scrolls from Cleric Ritual Spells . You start off a combination of six 1st level Wizard Spells and Cleric Spells . These spells can be ritual or non-ritual, but you can only cast them normally with your Artificer Spell Slots if they have the ritual tag.Starting at 3rd level, you can bend magic to assist or hinder creatures through the power of their true names, and even use those names as an anchor to affect others around them. Theandspells are Artificer spells for you, and you add them to your spellbook. You cvan cast both of these spells at a level equal to your proficiency bonus, a number of times equal to your Intelligence modifier (minimum of 1), and you regain all expended uses when you finish a long rest.Beginning at 5th level, when you use your action to use a Scroll, you can also use your bonus action to make a basic melee attack, or cast a cantrip.Starting at 9th level, as an action you can touch a creature that is possessed, expend a spell slot of 1st level or higher, and exorcise the presence. The target must succeed on a Wisdom saving throw against your Artificer Spell Save or be exorcised and banished to their home reality. Additionally you can cast theat a level equal to your proficiency bonus, and a number of times equal to your Intelligence modifier (minimum of 1). You regain all expended uses of this ability after a long rest.At 15th level, You have learned how to bypass a named creatures defenses against certain types of damage. When you cast a spell that deals damage to a creature whose True Name you speak as part of casting the spell, you can cause the spell to deal force or psychic damage to the creature, instead of the spells normal damage type.A recent innovation from the Halls of Stormwind and birthplace of the Warforged. Ambitious Artificers at the school managed to adapt the learning of mechanisation and automaton to armour. Designed to enhance the artificers magic, unleash potent attacks, and generate a formidable defense. The artificer bonds with a single set of powered armor, becoming one with it even as they experiment with it and refine its magical capabilities into a second skin.Cuirass (16 AC): 30lb, 75gp and Heater Shield (+2 AC): 8lb, 20gpLight Hammer (1d6 bludgeoning, range 20/60ft, Light): 2lb, 5gpAppraisal Kit (5gp), Smiths Tools (20gp), Leatherworking Kit (15gp), and Runecarvers Tools (50gp)Dungeoneers Pack (8gp) containing a backpack, a crowbar, a hammer, 10 pitons, 10 torches, 50ft of hemp rope, a tinderbox.When you adopt this specialization you gain proficiency with Heavy Armour and Weaving . Also when applying armour tags or creating armour, you take half the required amount of time for the work.You always have certain spells prepared after you reach particular levels in this class, as shown at the bottom of the Artificer Spell List . These spells count as artificer spells for you, but they dont count against the number of artificer spells you prepare.Your metallurgical pursuits have led to you making armour a conduit for your artificer magic. During a Long Rest, you can turn a suit of heavy armour you are wearing into power armour, provided you have smiths tools in hand. You gain the following benefits while wearing the power armour: The power armour attaches to you and cant be removed against your will. It also expands to cover your entire body, and it replaces any missing limbs, functioning identically to a body part it is replacing. While wearing power armour, melee weapons can use your Intelligence modifier, instead of Strength or Dexterity, for the attack and damage rolls. If the armour normally has a Strength requirement, the power armour lacks this requirement for you. You can use the power armour as a spellcasting focus for your artificer spells.The armour continues to be power armour until you create another set of Power Armour, or you die.Beginning at 3rd level, you have completed addition of repulsors in your armour. Your unarmed strikes now deal 1d8 + Intelligence modifier thunder damage, you can also fire off your gauntlets with a range of 20/60ft to deal 1d8 + Intelligence force damage. The gaunlets automatically return to the wearer and reattach to your armour. Your weapon attacks also deal an additional 1d4 force damage. A creature hit by your spells or weapons has disadvantage on attack rolls against targets other than you until the start of your next turn, as the armour magically emits a distracting pulse when the creature attacks someone else. You also gain a bonus action that you can use on each of your turns to gain temporary hit points equal to your level in this class, replacing any temporary hit points you already have. You lose these temporary hit points if you doff the armour.Starting at 5th level, you can attack twice, rather than once, whenever you take the Attack action on your turn.Beginning at 9th level, you learn how to use your artificer infusions to specially modify the armour enhanced by your Power Armor feature. That armour now counts as separate items for the purposes of your Infuse Items feature: armour (the chest piece), amulet, belt, boots, bracers, and rings. Each of those items can bear one of your infusions. In addition, the maximum number of items you can infuse at once increases by 2, but those extra items must be part of your power armour.At 15th level, tinkering with your armours energy system leads you to discover a powerful pulling force. When a creature you can see ends its turn within 30 feet of you, you can use your reaction to force the creature to succeed on a Strength saving throw against your spell save DC or be pulled up to 30 feet toward you to an unoccupied space. If you pull the target to space within 5 feet of you, you can make a melee weapon attack against it as part of this reaction. You can use this reaction a number of times equal to your Intelligence modifier (minimum of once). You regain all expended uses of it when you finish a long rest.The mastery of arcanotech Artillery is still one lead by Gnomes, the Gnomes of Lantans Rest that is. One of the smallest geographical settlements in the Sword Coast, their Skyships and Navy are universally feared for their legions of Artillerist artificers. Their destructive potential from a stationary point in unmatched except maybe by the highest of War Magics, with many other Navys paltry attempts producing a few capable Artillerists.Studded Leather (12 + Dex mod AC): 13lb, 45gpDagger (1d4 piercing, range 20/60ft, Finesse, Light): 1lb, 2gpSimple Flintlock (2d10 force, range 10/40ft, Loading): 5lb, 12gpThieves Tools (25gp), Scrimshaws Tools (15gp), Smiths Tools (20gp), and Leatherworking Kit (15gp).Burglars Pack (4gp) containing a backpack, a bag of 1,000 ball bearings, 50ft of hemp rope, string, bells, a crowbar, a hooded lantern, flasks of oil, tinderbox.When you adopt this specialization you gain proficiency with Carpentry and Siege Weapons . Also when applying weapon tags or creating weapons, you take half the required amount of time for the work. You can use your ranged weapons as a focus for your Artificer Spells You always have certain spells prepared after you reach particular levels in this class, as shown at the bottom of the Artificer Spell List . These spells count as Artificer Spells for you, but they dont count against the number of Artificer Spells you prepare.At 3rd level, you learn how to create a magical cannon, you can take an action to magically create a Small or Tiny eldritch cannon in an unoccupied space on a horizontal surface within 5 feet of you. A Small eldritch cannon occupies its space, and a Tiny one can be held in one hand. Once you create a cannon, you cant do so again until you finish a long rest or until you expend a spell slot of 1st level or higher. You can have only one cannon at a time and cant create one while your cannon is present. The cannon is a magical object. Regardless of size, the cannon has an AC of 18 and a number of hit points equal to five times your artificer level. It is immune to poison and psychic damage. If it is forced to make an ability check or a saving throw, treat all its ability scores as 10 (+0). If thespell is cast on it, it regains 2d6 hit points. It disappears if it is reduced to 0 hit points or after 1 hour. You can dismiss it early as an action. When you create the cannon, you determine its appearance and whether it has legs. You also decide which type it is, choosing from the options on the Eldritch Cannons table. On each of your turns, you can take a bonus action to cause the cannon to activate if you are within 60 feet of it. As part of the same bonus action, you can direct the cannon to walk or climb up to 15 feet to an unoccupied space, provided it has legs.The can non exhales fire in an adjacent 15-foot cone that you designate. Each creature in that area must make a Dexterity saving throw against your spell save DC, taking 2d8 fire damage on a failed save or half as much damage on a successful one. The fire ignites any flammable objects in the area that arent being worn or carried.Make a ranged spell attack, originating from the cannon, at one creature or object within 120 feet of it. On a hit, the target takes 2d8 force damage, and if the target is a creature, it is pushed up to 5 feet away from the cannon.The cannon emits a burst of positive energy that grants itself and each creature of your choice within 10 feet of it a number of temporary hit points equal to 1d8 + your Intelligence modifier (minimum of +1) .At 5th level, you know how to turn a wand, staff, or rod into an arcane firearm, a conduit for your destructive spells. When you finish a long rest, you can use woodcarvers tools to carve the material of a wand, staff, or rod and thereby turn it into a flintlock in addition to an arcane focus. The firearm turns back into its original form if you repeat this process on another Item. The change otherwise last indefinitely. When you cast an Artificer Spell through the firearm, roll a d8, and you gain a bonus to one of the spells damage rolls equal to the number rolled.Starting at 9th level, every eldritch cannon you create is more destructive: The cannons damage rolls all increase by 1d8. As an action, you can command the cannon to detonate if you are within 60 feet of it. Doing so destroys the cannon and forces each creature within 20 feet of it to make a Dexterity saving throw against your spell save DC, taking 3d8 force damage on a failed save or half as much damage on a successful one.Starting at 15th level, youre a master at forming well-defended emplacements using Eldritch Cannon: You and your allies have half cover while within 10 feet of a cannon you create with Eldritch Cannon, as a result of a shimmering field of magical protection that the cannon emits. You can now have two cannons at the same time. You can create two with the same action (but not the same spell slot), and you can activate both of them with the same bonus action. You determine whether the cannons are identical to each other or different. You cant create a third cannon while you have two.The newest of Dwarven ingenuity, mixing the lessons of their Gnomish allies with Dwarven martial tradition, comes the Battle Smith. Protected, mobile, and able to create a rolling defence crucial in the treacherous Underdark. A combination of protectorate and medic, a Battle Smith is an expert at defending others and repairing both material and personnel. To aid in their work, Battle Smiths are accompanied by a automaton called a steel defender, a protective companion of their own creation.Hauberk (13 + Dex mod [max 2] AC): 30lb, 60gp and Heater Shield (+2 AC): 8lb, 20gpWarhammer (1d8/d10 bludgeoning): 2lb, 15gp or Cavalry Mace (1d10 bludgeoning, Reach 1): 18lb, 35gp2 Light Hammer (1d6 bludgeoning, range 20/60ft, Light): 2lb, 5gpSteppe Pony (30gp)Smiths Tools (20gp)Dungeoneers Pack (8gp) containing a backpack, a crowbar, a hammer, 10 pitons, 10 torches, 50ft of hemp rope, a tinderbox.When you adopt this specialization you gain proficiency with Riding and Martial Weapons . Also, when you attack with a magic weapon, you can use your Intelligence modifier, instead of Strength or Dexterity modifier, for the attack and damage rolls. You can use your martial weapon as a focus for your artificer spells.You always have certain spells prepared after you reach particular levels in this class, as shown at the bottom of the Artificer Spell List . These spells count as Artificer Spells for you, but they dont count against the number of Artificer Spells you prepare.By 3rd level, your tinkering has borne you a faithful companion, a steel defender. It is friendly to you and your companions, it defaults to a Dodge Action, unless you spend a Bonus action to make it Rend, Repair, Dash, Disengage, Help, Hide or Search. If you are incapacitated, the defender can take any action of its choice, not just Dodge.152 + your Intelligence modifier +5 times your artificer level40ftDarkvision 60ft14 (+2)12 (+1)14 (+2)4 (-4)10 (+0)6 (-2)Dex +1 + Proficiency Bonus, Con +2 + Proficiency Bonus.Athletics +2 + Proficiency Bonus, Perception +Proficiency Bonus x 2Charmed, Disease, Exhaustion, Poison, Surprise+spell attack modifier to hit, 1d8 +proficiency bonus force damage.The magical mechanisms inside the defender restore 2d8 +Proficiency Bonus hit points to itself or to one construct or object within 5 feet of it.The defender imposes disadvantage on the attack roll of one creature it can see that is within 5 feet of it, provided the attack roll is against a creature other than the defender.You determine the creatures appearance and whether it has two legs or four; your choice has no effect on its game statistics. If thespell is cast on it, it regains 2d6 hit points. If it has died within the last hour, you can use your smiths tools as an action to revive it, provided you are within 5 feet of it and you expend a spell slot of 1st level or higher. The steel defender returns to life after 1 minute with all its hit points restored. At the end of a long rest, you can create a new steel defender if you have your smiths tools with you. If you already have a steel defender from this feature, the first one immediately perishes.Starting at 5th level, you can attack twice, rather than once, whenever you take the Attack action on your turn.At 9th level, you learn new ways to channel arcane energy to harm or heal. When either you hit a target with a magic weapon attack or your steel defender hits a target, you can channel magical energy through the strike to create one of the following effects: The target takes an extra 2d6 force damage. Choose one creature or object you can see within 30 feet of the target. Healing energy flows into the chosen recipient, restoring 2d6 hit points to it.You can use this energy a number of times equal to your Intelligence modifier (minimum of once), but you can do so no more than once on a turn. You regain all expended uses when you finish a long rest.At 15th level, your Arcane jolt and steel defender become more powerful: The extra damage and the healing of your Arcane jolt both increase to 4d6. Your steel defender gains a +2 bonus to Armor Class and a 80ft flying speed. Whenever your steel defender uses its Deflect Attack, the attacker takes force damage equal to 1d4 + your Intelligence modifier.Teleportation has always been a popular path of arcane study, with most falling into the traditional methods tried and tested by braver spellcrafters. But never before has such a bone-headed and crazy level of experimental risk been taken before. The Portal Engineers of the Waterdeep and Illusk took the higher craft of Planeswalkers and reduced it into the most basic of abilities. And now they abuse the laws of the cosmos for quick hop and a skip around townStudded Leather (12 + Dex mod AC): 13lb, 45gpDagger (1d4 piercing, range 20/60ft, Finesse, Light): 1lb, 2gpSimple Flintlock (2d10 force, range 10/40ft, Loading): 5lb, 12gpThieves Tools (25gp), Astronomy Equipment (35gp), and Planewalkers Case (65gp)Burglars Pack (4gp) containing a backpack, a bag of 1,000 ball bearings, 50ft of hemp rope, string, bells, a crowbar, a hooded lantern, flasks of oil, tinderbox.When you adopt this specialization you gain proficiency with Astrology and you can teleport objects that are less than 10 pounds unless their are worn or held by a hostile creature. You can also use items from other planes as spellcasting foci for your Artificer Spells You always have certain spells prepared after you reach particular levels in this class, as shown at the bottom of the Artificer Spell List . These spells count as Artificer Spells for you, but they dont count against the number of Artificer Spells you prepare.At 3rd level, you have mastered the art of creating portals. Using your bonus action, you create a portal within 30ft, the portal is 3 feet wide and 6 feet tall, and connect it to another portal within 30ft as the same size. Spells cannot travel through the portal but ranged attacks can. A creature must be willing to enter the portal to use it. This ability can be used a number of times equal to your Intelligence modifier, you regain all expended uses of this ability on a long rest. This range increases to 60ft at 9th level. Additionally, your weapon deals an additional 1d8 force damage through portal energy, this increases to 2d8 at 9th level.Starting at 5th level, youve learnt to channel your teleportation energy into those who travel through it. Once per round when a creature moves through your portal, they deal an additional 1d8 force damage to their attack. This increases to twice per round at 9th level, and three times per round at 15th level. You can choose to obscure the view of the portal, choose to make it one-way, or two-way obscurement.At 9th level, youve learnt to teleport creatures other than yourself. As a reaction you can move an ally within 60ft of you anywhere else within 60ft of you. You regain the use of this ability on a short or long rest. Your portals can now also be used to teleport unwilling creatures that move through it.At 15th level, you can castorwithout having the spell prepared. You regain this ability on a long rest.A newly formed specialty of artifice using complex pulleys and nearly in-perceivable strings to move creatures and objects and control the world around you. While most artificers are overt and dangerously direct, you can appear harmless and unseen if you need to.Hauberk (13 + Dex mod [max 2] AC): 30lb, 60gpDagger (1d4 piercing, range 20/60ft, Finesse, Light): 1lb, 2gpSimple Flintlock (2d10 force, range 10/40ft, Loading): 5lb, 12gpThieves Tools (25gp)Burglars Pack (4gp) containing a backpack, a bag of 1,000 ball bearings, 50ft of hemp rope, string, bells, a crowbar, a hooded lantern, flasks of oil, tinderbox.When you adopt this specialization you gain proficiency with Weaving Carpentry , and three string-based Instruments of your choice. You can also use Instruments as spellcasting foci for your Artificer Spells You always have certain spells prepared after you reach particular levels in this class, as shown at the bottom of the Artificer Spell List . These spells count as Artificer Spells for you, but they dont count against the number of Artificer Spells you prepare.At 3rd level, you can bind a creature within 60ft to yourself with silk string, channeling energy to and from them. Once you create a magical string, you cant do so again until you finish a long rest or until you expend a spell slot of 1st level or higher. You can only have one magical string at a time. If you create a new one, the original one loses its magic. The string also loses its magic after 1 hour, and you can dismiss its magic early as an action. This connection remains even if the creature moves out of range. As an action on each of your turns, you can reconnect the string to another creature. This connection ends when the string loses its magic. You can target the represented creature with spells that have a range of Touch, by casting such a spell on the string. As a bonus action on each of your turns, you can expose the string to a harmful effect within 5 feet of you to potentially damage the connected creature. The harmful effect must deal bludgeoning, piercing, slashing, acid, cold, fire, lightning, necrotic, radiant, or thunder damage. When you affect the string, the represented creature must succeed on a Wisdom saving throw or else take 2d8 of the corresponding damage type. If you use your action to cast a spell that deals a qualifying type of damage, you can choose for the string connection to deal that type of damage. For example, if you use your action to cast, you can choose for the effigy connection to deal cold damage, regardless of whether you exposed the effigy to the actual spell effects or not.Starting at 5th level, if your stringed creature makes a Strength or Dexterity based saving throw, attack roll, or ability check, you can use your reaction to force them to do it with advantage or disadvantage (your choice).Beginning at 9th level, the damage rolls caused by your string increase by 1d8. As an action, you can see through the creatures eyes and hear what it hears, and continue to do so until you use your action to return to your normal senses or until the string disappears. The creature is aware someone is perceiving through its senses, but does not necessarily know who it is or how they can do it.At 15th level, you have become a master of control. You can caston a stringed creature once without expending a spell slot. Once you have used this feature, you cannot use it again until you finish a long rest.Most artificers are focused on stability and reliability. Now, reliability is always nice, but you were intensely interested in the unstable. The explosive, best executed in the enemies faces. Stealth and knowledge of your surrounding are your bread and butter more than the explosives you covet, but you also have the quickness of hand to deploy mid-combat in a pinch if caught unawares. But hopefully they never hear you coming just your arrival.Studded Leather (12 + Dex mod AC): 13lb, 45gpLongbow (1d8 piercing, range 150/600ft, Ammunition, Heavy, Two-Handed): 2lb, 50gp2 Daggers (1d4 piercing, range 20/60ft, Finesse, Light): 1lb, 2gpThieves Tools (25gp), Alchemists Station (50gp)Burglars Pack (4gp) containing a backpack, a bag of 1,000 ball bearings, 50ft of hemp rope, string, bells, a crowbar, a hooded lantern, flasks of oil, tinderbox.When you adopt this specialization you gain proficiency with Poisoning Longbows and Stealth checks. You also know thecantrip.You always have certain spells prepared after you reach particular levels in this class, as shown at the bottom of the Artificer Spell List . These spells count as Artificer Spells for you, but they dont count against the number of Artificer Spells you prepare.You have learned to further enhance the magical affects of. When you cas the spell, you have advantage on Lore checks about your marked target and learn vulnerabilities and saving throws. You can cast the spell at 1st level a number of times equal to your proficiency bonus without using a spell slot. You regain all expended uses of this feature on a long rest.Starting at 3rd level, you learn how to create a deployable wall. You can use your action to deploy a semi-circle wall of half cover that is 15 feet diameter and 2 feet thick, originating at a point you can see within 60 feet. This cover has an AC of 10 + your Intelligence modifier and a number of hit points equalling ten times your Intelligence modifier. It is immune to poison damage, psychic damage, and all conditions. If it is forced to make an ability check or a saving throw, treat all its ability scores as 10 (+0). If thespell is cast on it, it regains 2d6 hit points. It disappears if it is reduced to 0 hit points or after 1 hour. You can dismiss it early as an action. Once you create the barricade, you cant do so again until you finish a long rest or until you expend a spell slot of 1st level or higher. You can only have one barricade at a time and cant create one while your barricade is present. When you create cover, your allies gain the following additional effects below:As a bonus action on your turn, you can activate the protective energies within your barricade. When you activate this feature, all friendly creatures within 30ft of your cover gain 1d8 + Intelligence modifier temporary hit points.This explosive barrier is built for defense. As a reaction, when your cover or an ally protected by your cover would be hit by an attack, you can activate this barricade to make a spell attack damage or deal 2d8 force damage to the attacker.Starting at 5th level, you can now create cover with your bonus action. The wall is now a full circle. In addition, you are able to take better aim from behind your cover. Once on each of your turns, while within 5ft of your cover when you hit a creature with an attack, you can cause the attack to deal an additionally 1d8 force damage to the target. When you reach 15th level, the extra damage increases to 2d8.At 9th level, the cover you create for others is charged with extra power. Rapid Deployment, Hospitality, and Reflection gain an additional 1d8 to their respective healing or damage.At 15th level, you are masterful at keeping others safe. The cover you can build gains the following upgrades: Benefits of your cover gains an additional +2 to its Armour Class. Grants advantage against Area of Affect spells that target behind cover.
Several fundamental data types involve collections of objects.
Specifically, the set of values is a collection of objects,
and the operations revolve around adding, removing, or examining
objects in the collection. In this section,
we consider three such data types, known as the bag, the queue,
and the stack. They differ in the specification of which object is to be
removed or examined next.
We define the APIs for bags, queues, and stacks. Beyond the basics, these APIs reflect two Java features: generics and iterable collections.
to use a stack for String objects.Stack<String> stack = new Stack<String>(); stack.push("Test"); ... String next = stack.pop();
Automatically casting a primitive type to a wrapper type is known as autoboxing, and automatically casting a wrapper type to a primitive type is known as unboxing.Stack<Integer> stack = new Stack<Integer>(); stack.push(17); // autoboxing (int -> Integer) int i = stack.pop(); // unboxing (Integer -> int)
for (Transaction t : collection) StdOut.println(t);
This code is a simple example of an interpreter.
private class Node { Item item; Node next; }
for (Node x = first; x != null; x = x.next) { // process x.item }
A linked list is a recursive data structure that is either empty (null) or a reference to a node having a generic item and a reference to a linked list. To implement a linked list, we start with a nested class that defines the node abstraction
This foreach statement is shorthand for the following while statement:Stack<String> collection = new Stack<String>(); ... for (String s : collection) StdOut.println(s); ...
To implement iteration in a collection:Iterator<String> i = collection.iterator(); while (i.hasNext()) { String s = i.next(); StdOut.println(s); }
import java.util.Iterator;
implements Iterable<Item>
public Iterator<Item> iterator() { return new LinkedIterator(); }
This foreach statement is shorthand for the followingstatement:To implement iteration in a collection:
Q. How does autoboxing handle the following code fragment?
Integer a = null; int b = a;
A. It results in a run-time error. Primitive type can store every value of their corresponding wrapper type except null.
Q. Why does the first group of statements print true, but the second false?
Integer a1 = 100; Integer a2 = 100; System.out.println(a1 == a2); // true Integer b1 = new Integer(100); Integer b2 = new Integer(100); System.out.println(b1 == b2); // false Integer c1 = 150; Integer c2 = 150; System.out.println(c1 == c2); // false
A. The second prints false because b1 and b2 are references to different Integer objects. The first and third code fragments rely on autoboxing. Surprisingly the first prints true because values between -128 and 127 appear to refer to the same immutable Integer objects (Java's implementation of valueOf() retrieves a cached values if the integer is between -128 and 127), while Java constructs new objects for each integer outside this range.
Here is another Autoboxing.java anomaly.
Q. Are generics solely for auto-casting?
A. No, but we will use them only for "concrete parameterized types", where each data type is parameterized by a single type. The primary benefit is to discover type-mismatch errors at compile time instead of run time. There are other more general (and more complicated) uses of generics, including wildcards. This generality is useful for handling subtypes and inheritance. For more information, see this Generics FAQ and this Java generics tutorial.
Q. Can concrete parameterized types be used in the same way as normal types?
A. Yes, with a few exceptions (array creation, exception handling, with instanceof, and in a class literal).
Q. Can I make the Node class static?
A. For LinkedStackOfString.java, you can do so with no other changes and save 8 bytes (of inner class overhead) per node. However, the nested class Node in LinkedStack.java uses the type information of Item from the outer class, so you would need to do a bit of extra work to make it static. Stack.java accomplishes this by making the nested class (and the nester iterator) generic: there are three separate generic type parameters, each of which is named Item.
Q. Why do I get a "can't create an array of generics" error when I try to create an array of generics?
public class ResizingArrayStack<Item> { Item[] a = new Item[1];
A. Unfortunately, creating arrays of generics is not possible in Java 1.5. The underlying cause is that arrays in Java are covariant, but generics are not. In other words, String[] is a subtype of Object[], but Stack<String> is not a subtype of Stack<Object>. To get around this defect, you need to perform an unchecked cast as in ResizingArrayStack.java. ResizingArrayStackWithReflection.java is an (unwieldy) alternative that avoids the unchecked cast by using reflection.
Q. So, why are arrays covariant?
A. Many programmers (and programming language theorists) consider covariant arrays to be a serious defect in Java's type system: they incur unnecessary run-time performance overhead (for example, see ArrayStoreException) and can lead to subtle bugs. Covariant arrays were introduced in Java to circumvent the problem that Java didn't originally include generics in its design, e.g., to implement Arrays.sort(Comparable[]) and have it be callable with an input array of type String[].
Q. Can I create and return a new array of a parameterized type, e.g., to implement a toArray() method for a generic queue?
A. Not easily. You can do it using reflection provided that the client passes an object of the desired concrete type to toArray() This is the (awkward) approach taken by Java's Collection Framework. GenericArrayFactory.java provides an alternate solution in which the client passes a variable of type Class. See also Neal Gafter's blog for a solution that uses type tokens.
Q. Why is the construct called foreach if it uses the keyword for?
A. Other languages use the keyword foreach, but the Java developers did not want to introduce a new keyword and break backward compatibility.
Q. Are Strings iterable?
A. No.
Q. Are arrays Iterable?
A. No. You can use the foreach syntax with them. However, you can not pass an array to a method that expects an Iterable or return an array from a method which returns an Iterable. This would be convenient, but it doesn't work that way.
Q. What's wrong with the following code fragment?
String s; for (s : listOfStrings) System.out.println(s);
A. The enhanced for loop requires that the iterating variable be declared inside the loop.
Solution. was best times of the was the it (1 left on stack)it was - the best - of times - - - it was - the - -
(a) 4 3 2 1 0 9 8 7 6 5 (b) 4 6 8 7 5 3 2 9 0 1 (c) 2 5 6 7 4 8 9 3 1 0 (d) 4 3 2 1 0 5 6 7 8 9 (e) 1 2 3 4 5 6 9 8 7 0 (f) 0 4 6 5 3 8 1 7 2 9 (g) 1 4 7 9 8 6 5 3 0 2 (h) 2 1 4 3 6 5 8 7 9 0
Answer: (b), (f), and (g).
Stack<Integer> s = new Stack<Integer>(); while (n > 0) { s.push(n % 2); n = n / 2; } while (!s.isEmpty()) System.out.print(s.pop()); System.out.println();
Answer: Prints the binary representation of N ( when n is 50).
Answer: Reverses the items on the queue.Stack<String> s = new Stack<String>(); while(!q.isEmpty()) s.push(q.dequeue()); while(!s.isEmpty()) q.enqueue(s.pop());
Answer: (b), (c), and (d).(a) 0 1 2 3 4 5 6 7 8 9 (b) 4 6 8 7 5 3 2 9 0 1 (c) 2 5 6 7 4 8 9 3 1 0 (d) 4 3 2 1 0 5 6 7 8 9
Solution: ResizingArrayQueue.java
% java Josephus 2 7 1 3 5 0 4 2 6
Recursive solution: create a copy constructor for a linked list starting at a given Node and use this to create the new stack.
Node(Node x) { item = x.item; if (x.next != null) next = new Node(x.next); } public Stack(Stack<Item> s) { first = new Node(s.first); }
Nonrecursive solution: create a copy constructor for a single Node object.
Node(Node x) { this.item = x.item; this.next = x.next; } public Stack(Stack<Item> s) { if (s.first != null) { first = new Node(s.first); for (Node x = first; x.next != null; x = x.next) x.next = new Node(x.next); } }
Solution. The stack does not underflow unless there exists an integer k such that the first k pop operations occur before the first k push operations.
If a given permutation can be generated, it is uniquely generated as follows: if the next integer in the permutation is in the top of the stack, pop it; otherwise, push the next integer in the input sequence onto the stack (or stop if N-1 has already been pushed). The permutation can be generated if and only if the stack is empty upon termination.
Partial solution. Suppose that there is a forbidden triple (a, b, c). Item c is popped before a and b, but a and b are pushed before c. Thus, when c is pushed, both a and b are on the stack. Therefore, a cannot be popped before b.
Solution: Maintain a counter that counts the number of push() and pop() operations. When creating an iterator, store this value as an iterator instance variable. Before each call to hasNext() and next(), check that this value has not changed since construction of the iterator; if it has, throw an exception.
Hint: use two stacks, one to store all of the elements and a second stack to store the maximums.
since as a result of floating point precision, the loop will execute 10N times if N = xxx, and 10N + 1 times if N = yyy. Create an data type Mesh so that x ranges from left to right in increments of size delta. Assuming right >= left, the loop should execute exactly If 1 + floor((right - left) / delta) times.for (double x = 0.0; x <= N; x += 0.1) { .. }
This is how the colon operator works in MATLAB. You should also instrument your program so that it works even left > right and delta is negative.for (double x : new Mesh(left, right, delta)) { .. }
We use a dummy head and tail node to avoid extra cases. We also store an extra variable lastAccessed which stores the node accessed in the most recent call to next() or previous(). After removing an element, we reset lastAccessed to null; this designates that calling remove() is illegal (until after a subsequent call to either next() or previous().
Hint: iterate through the items of b using an iterator, and add each to the end of the invoking bag.
Answer: stack overflow. The Java documents says that "while it is permissible for lists to contain themselves as elements, extreme caution is advised: the equals and hashCode methods are no longer well defined on a such a list."List list1 = new ArrayList(); List list2 = new ArrayList(); list1.add(list2); list2.add(list1); System.out.println(list1.equals(list2)); List list = new ArrayList(); list.add(list); System.out.println(list.hashCode());
No. It will print out 10 values, but with some duplicates and not in ascending order. The iterator does not save a copy of the original array - instead, it uses the mutated copy.int[] vals = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; for (int val : vals) { System.out.print(val + " "); StdRandom.shuffle(vals); // mutate the array while iterating } System.out.println();
Solution: QueueWithTwoStacks.java.
Answer: for each query word, create a sorted list of the indices where it appears in the document. Scan through lists 2 to k in that order, deleting indices at the front of each list until the the first elements of the resulting k lists are in ascending order.
The sequence of first elements on the lists forms the shortest interval containing the first element on list 1.q[1]: 50 123 555 q[2]: 33 44 93 333 606 613 q[3]: 60 200 q[4]: 12 18 44 55 203 495 q[1]: 50 123 555 q[2]: 93 333 606 613 q[3]: 200 q[4]: 203 495
Now delete the first element on list 1. Repeatedly delete elements from list 2 until it agrees with list 1. Repeat for list 3, and so on until the whole array is in ascending order. Check this sequence of first elements, etc.
Analysis of M/M/1 model. We are interested in understanding the queueing system. If &lambda > μ the queue size increases without limit. For simple models like M/M/1 we can analyze these quantities analytically using probability theory. Assuming μ > λ, the probability of exactly n customers in the system is (λ / μ)^n (1 - λ / &mu).
Program MM1Queue.java For more complex models we need to resort to simulation like this. Variants: multiple queues, multiple servers, sequential multi-stage servers, using a finite queue and measuring number of customers that are turned away. Applications: customers in McDonalds, packets in an internet router,
Queue<Integer> q = new Queue<Integer>(); q.enqueue(0); q.enqueue(1); for (int i = 0; i < 10; i++) { int a = q.dequeue(); int b = q.dequeue(); q.enqueue(b); q.enqueue(a + b); System.out.println(a); }
public void push(Item item) { Node second = first; Node first = new Node(); first.item = item; first.next = second; }
Answer: By redeclaring first, you are create a new local variable named first, which is different from the instance variable named first.
Solution:: maintain two stacks, one which contains all of the items and another which contains the minima. To push an item, push it on the first stack; if it is smaller than the topmost item on the second stack, push it on the second stack as well. To pop an item, pop it from the first stack; if it is the top item on the second stack, pop it from the second stack as well. To find the minimum, return the top item on the second stack.
prices[]
, create
an array days[]
so that days[i]
tells you how
many days you have to wait, starting at day i
, until the
stock price exceeds prices[i]
.
Hint: your algorithm should take linear time and use a stack of array indices.
If you want to learn more, please visit our website Casting Foundry Gate Filter.
If you are interested in sending in a Guest Blogger Submission,welcome to write for us!
All Comments ( 0 )